def test_hash(self):
        d1 = VariableDomain("d", "foo", [1, 2, 3])
        v1 = VariableWithCostDict("v1", d1, {1: 1, 2: 2, 3: 3})
        v1_othercosts = VariableWithCostDict("v1", d1, {1: 2, 2: 2, 3: 3})

        self.assertNotEqual(hash(v1), hash(v1_othercosts))

        v1_othername = VariableWithCostDict("v1_other", d1, {1: 1, 2: 2, 3: 3})

        self.assertNotEqual(hash(v1), hash(v1_othername))

        self.assertEqual(
            hash(v1), hash(VariableWithCostDict("v1", d1, {1: 1, 2: 2, 3: 3}))
        )
Beispiel #2
0
    def test_hash(self):
        d1 = VariableDomain('d', 'foo', [1, 2, 3])
        v1 = VariableWithCostDict('v1', d1, {1: 1, 2: 2, 3: 3})
        v1_othercosts = VariableWithCostDict('v1', d1, {1: 2, 2: 2, 3: 3})

        self.assertNotEqual(hash(v1), hash(v1_othercosts))

        v1_othername = VariableWithCostDict('v1_other', d1, {1: 1, 2: 2, 3: 3})

        self.assertNotEqual(hash(v1), hash(v1_othername))

        self.assertEqual(
            hash(v1), hash(VariableWithCostDict('v1', d1, {
                1: 1,
                2: 2,
                3: 3
            })))
Beispiel #3
0
    def test_cost_dict_from_repr(self):
        v1 = VariableWithCostDict('v1', [1, 2, 3], {1: 0.5, 2: 0.8, 3: 1})
        r = simple_repr(v1)
        v2 = from_repr(r)

        self.assertEqual(v1, v2)
Beispiel #4
0
    def test_cost_dict_simple_repr(self):
        v1 = VariableWithCostDict('v1', [1, 2, 3], {1: 0.5, 2: 0.8, 3: 1})
        r = simple_repr(v1)

        self.assertEqual(r['costs'], {1: 0.5, 2: 0.8, 3: 1})
Beispiel #5
0
    def test_cost_dict(self):
        v1 = VariableWithCostDict('v1', [1, 2, 3], {1: 0.5, 2: 0.8, 3: 1})

        self.assertEqual(v1.cost_for_val(3), 1)