def test_choice_type_raises_error_if_different_output_numbers(self): with self.assertRaises(ValueError): ChoiceType([ SimpleType('int'), ParallelType([SimpleType('int'), SimpleType('float')]) ])
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())
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())
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')])))
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')])))
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')])))
def test_simple_types_are_equals_if_same_name(self): self.assertEqual(SimpleType('int'), SimpleType('int')) self.assertEqual(hash(SimpleType('int')), hash(SimpleType('int')))
def test_choice_types_are_different_if_different_num_outputs(self): self.assertNotEqual( ChoiceType([SimpleType('int')]), ChoiceType([SimpleType('int'), SimpleType('float')]))
def test_parallel_types_are_different_if_different_num_outputs(self): self.assertNotEqual( ParallelType([SimpleType('int')]), ParallelType([SimpleType('int'), SimpleType('float')]))
def test_simple_types_are_different_from_just_the_name(self): self.assertNotEqual(SimpleType('float'), 'int')
def test_simple_types_are_different_if_different_name(self): self.assertNotEqual(SimpleType('float'), SimpleType('int'))
def test_compatibility(self): compat = MockLibrary().compatibility() self.assertEqual( SimpleType('a'), compat.get_upperbound(SimpleType('a'), SimpleType('b')))