Esempio n. 1
0
 def test_choice_type_raises_error_if_different_output_numbers(self):
     with self.assertRaises(ValueError):
         ChoiceType([
             SimpleType('int'),
             ParallelType([SimpleType('int'),
                           SimpleType('float')])
         ])
Esempio n. 2
0
 def test_can_register_a_variable(self):
     library = MockLibrary()
     library.register_variable('ciao', 1.0, SimpleType('float'))
     expected_env = {
         'ciao': 1.0,
         '::types::': {
             'ciao': SimpleType('float')
         }
     }
     self.assertEqual(expected_env, library.env())
Esempio n. 3
0
 def test_can_register_a_function(self):
     library = MockLibrary()
     library.register_function('ciao', float, [SimpleType('int')],
                               SimpleType('float'))
     expected_func_env = {
         'ciao': float,
         '::types::': {
             'ciao': ([SimpleType('int')], SimpleType('float'))
         }
     }
     self.assertEqual(expected_func_env, library.func_env())
Esempio n. 4
0
 def test_choice_types_are_equals_if_equal_subtypes_unordered(self):
     self.assertEqual(ChoiceType([SimpleType('int'),
                                  SimpleType('float')]),
                      ChoiceType([SimpleType('float'),
                                  SimpleType('int')]))
     self.assertEqual(
         hash(ChoiceType([SimpleType('int'),
                          SimpleType('float')])),
         hash(ChoiceType([SimpleType('float'),
                          SimpleType('int')])))
Esempio n. 5
0
 def test_parallel_types_are_equals_if_equal_subtypes(self):
     self.assertEqual(
         ParallelType([SimpleType('int'),
                       SimpleType('float')]),
         ParallelType([SimpleType('int'),
                       SimpleType('float')]))
     self.assertEqual(
         hash(ParallelType([SimpleType('int'),
                            SimpleType('float')])),
         hash(ParallelType([SimpleType('int'),
                            SimpleType('float')])))
Esempio n. 6
0
 def test_choice_types_do_not_keep_duplicates(self):
     self.assertEqual(ChoiceType([SimpleType('int'),
                                  SimpleType('int')]),
                      ChoiceType([SimpleType('int')]))
     self.assertEqual(
         hash(ChoiceType([SimpleType('int'),
                          SimpleType('int')])),
         hash(ChoiceType([SimpleType('int')])))
Esempio n. 7
0
 def test_simple_types_are_equals_if_same_name(self):
     self.assertEqual(SimpleType('int'), SimpleType('int'))
     self.assertEqual(hash(SimpleType('int')), hash(SimpleType('int')))
Esempio n. 8
0
 def test_choice_types_are_different_if_different_num_outputs(self):
     self.assertNotEqual(
         ChoiceType([SimpleType('int')]),
         ChoiceType([SimpleType('int'),
                     SimpleType('float')]))
Esempio n. 9
0
 def test_parallel_types_are_different_if_different_num_outputs(self):
     self.assertNotEqual(
         ParallelType([SimpleType('int')]),
         ParallelType([SimpleType('int'),
                       SimpleType('float')]))
Esempio n. 10
0
 def test_simple_types_are_different_from_just_the_name(self):
     self.assertNotEqual(SimpleType('float'), 'int')
Esempio n. 11
0
 def test_simple_types_are_different_if_different_name(self):
     self.assertNotEqual(SimpleType('float'), SimpleType('int'))
Esempio n. 12
0
 def test_compatibility(self):
     compat = MockLibrary().compatibility()
     self.assertEqual(
         SimpleType('a'),
         compat.get_upperbound(SimpleType('a'), SimpleType('b')))