Ejemplo n.º 1
0
 def test_equal_transformer_have_same_hash(self):
     transformer = ChoiceTransformer(2, 0.3, 0.3)
     other_transformer = ChoiceTransformer(2, 0.3, 0.3)
     self.assertEqual(hash(transformer), hash(other_transformer))
Ejemplo n.º 2
0
 def test_equal_transformer_are_equal(self):
     transformer = ChoiceTransformer(2, 0.3, 0.3)
     other_transformer = ChoiceTransformer(2, 0.3, 0.3)
     self.assertEqual(transformer, other_transformer)
Ejemplo n.º 3
0
 def test_different_transformer_are_not_equal(self):
     transformer = ChoiceTransformer(2, 0.3, 0.3)
     other_transformer = ChoiceTransformer(2, 0.25, 0.3)
     self.assertNotEqual(transformer, other_transformer)
Ejemplo n.º 4
0
 def test_always_return_none_if_probability_sum_is_zero(self):
     transformer = ChoiceTransformer(2, 0.0, 0.0)
     for _ in range(10):
         self.assertEqual((None, ), transformer([0, 1]))
Ejemplo n.º 5
0
 def test_returns_all_values_and_none_if_probability_is_not_zero_or_one_and_sums_less_than_1(
         self):
     transformer = ChoiceTransformer(2, 0.3, 0.3)
     self.assertEqual({0, 1, None},
                      {transformer([0, 1])[0]
                       for _ in range(50)})
Ejemplo n.º 6
0
 def test_always_return_right_input_if_probability_is_one(self):
     transformer = ChoiceTransformer(2, 0.0, 1.0)
     for _ in range(10):
         self.assertEqual([1], transformer([0, 1]))
Ejemplo n.º 7
0
 def test_raises_error_if_too_few_inputs(self):
     transformer = ChoiceTransformer(2, 0.5, 0.5)
     with self.assertRaises(ValueError):
         transformer([0])
Ejemplo n.º 8
0
 def test_raises_error_if_config_sum_is_out_of_range(self):
     with self.assertRaises(ValueError):
         ChoiceTransformer(2, 0.75, 0.75)
Ejemplo n.º 9
0
 def test_raises_error_if_right_config_is_out_of_range(self):
     with self.assertRaises(TypeError):
         ChoiceTransformer(2, 0.5, 2.0)
Ejemplo n.º 10
0
 def test_raises_error_if_right_config_is_not_a_number(self):
     with self.assertRaises(TypeError):
         ChoiceTransformer(2, 1, "something")