<commit_before>#!/usr/bin/env python
"""
:Author <NAME>
:Created 23.06.2017 16:39
:Licence GNUv3
Part of grammpy

"""
from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class NonterminalAddRemoveMixedTest(TestCase):
    def test_add_remove_add_one(self):
        gr = Grammar()
        self.assertEqual(gr.nonterms_count(), 0)
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.nonterm(TempClass))
        gr.add_nonterm(TempClass)
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        gr.remove_nonterm(TempClass)
        self.assertEqual(gr.nonterms_count(), 0)
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.nonterm(TempClass))

    def test_addTwoRemoveOneAndAddThird(self):
        gr = Grammar()
        gr.add_nonterm(TempClass)
        gr.add_nonterm(Second)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.get_nonterm(Second), Second)
        gr.remove_nonterm(Second)
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        self.assertIsNone(gr.get_nonterm(Second))
        gr.add_term(Third)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)
        self.assertFalse(gr.have_nonterm(Second))
        self.assertIsNone(gr.nonterm(Second))
        self.assertIsNotNone(gr.get_nonterm(Third))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.get_nonterm(Third), Third)

    def test_addThreeRemoveTwoInArray(self):
        gr = Grammar()
        gr.add_nonterm([TempClass, Second, Third])
        self.assertEqual(gr.nonterms_count(), 3)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.nonterm(Second), Second)
        self.assertIsNotNone(gr.get_nonterm(Third))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.nonterm(Third), Third)
        gr.remove_term([Third, TempClass])
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertTrue(gr.have_nonterm(Second))
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertFalse(gr.have_nonterm(Third))
        gr.add_nonterm(Third)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.nonterm(Second), Second)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.nonterm(Third), Third)
        self.assertIsNotNone(gr.get_nonterm(Third))


if __name__ == '__main__':
    main()<commit_msg>Correct some usage of terms functions in nonterms tests<commit_after>#!/usr/bin/env python
"""
:Author <NAME>
:Created 23.06.2017 16:39
:Licence GNUv3
Part of grammpy

"""
from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class NonterminalAddRemoveMixedTest(TestCase):
    def test_add_remove_add_one(self):
        gr = Grammar()
        self.assertEqual(gr.nonterms_count(), 0)
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.nonterm(TempClass))
        gr.add_nonterm(TempClass)
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        gr.remove_nonterm(TempClass)
        self.assertEqual(gr.nonterms_count(), 0)
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.nonterm(TempClass))

    def test_addTwoRemoveOneAndAddThird(self):
        gr = Grammar()
        gr.add_nonterm(TempClass)
        gr.add_nonterm(Second)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.get_nonterm(Second), Second)
        gr.remove_nonterm(Second)
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        self.assertIsNone(gr.get_nonterm(Second))
        gr.add_nonterm(Third)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)
        self.assertFalse(gr.have_nonterm(Second))
        self.assertIsNone(gr.nonterm(Second))
        self.assertIsNotNone(gr.get_nonterm(Third))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.get_nonterm(Third), Third)

    def test_addThreeRemoveTwoInArray(self):
        gr = Grammar()
        gr.add_nonterm([TempClass, Second, Third])
        self.assertEqual(gr.nonterms_count(), 3)
        self.assertIsNotNone(gr.get_nonterm(TempClass))
        self.assertIsNotNone(gr.nonterm(TempClass))
        self.assertEqual(gr.nonterm(TempClass), TempClass)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.nonterm(Second), Second)
        self.assertIsNotNone(gr.get_nonterm(Third))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.nonterm(Third), Third)
        gr.remove_nonterm([Third, TempClass])
        self.assertEqual(gr.nonterms_count(), 1)
        self.assertTrue(gr.have_nonterm(Second))
        self.assertFalse(gr.have_nonterm(TempClass))
        self.assertFalse(gr.have_nonterm(Third))
        gr.add_nonterm(Third)
        self.assertEqual(gr.nonterms_count(), 2)
        self.assertIsNotNone(gr.nonterm(Second))
        self.assertEqual(gr.nonterm(Second), Second)
        self.assertIsNotNone(gr.get_nonterm(Second))
        self.assertIsNotNone(gr.nonterm(Third))
        self.assertEqual(gr.nonterm(Third), Third)
        self.assertIsNotNone(gr.get_nonterm(Third))


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.11544544016868741, 'fraction_numerical': 0.005798629414865577, 'mean_word_length': 3.5253428741800836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5451279', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2437, 'n_words': 283}