예제 #1
0
    def test_no_gold(self):
        le = ULedger(0)
        for i in range(0):
            t = UTransaction(mocksubject(-1), 0)
            le.add(t)

        assert le.recalculate() == (0.5, 0.5)
예제 #2
0
    def test_add_backupdaterecalculate(self, mock):
        le = ULedger(0)
        mock.reset_mock()
        t = UTransaction(mocksubject(0), 0)
        le.add(t)

        assert mock.call_count == 0
예제 #3
0
    def test_add_legacyrecalculate(self, mock):
        le = ULedger(0)
        mock.reset_mock()

        t = UTransaction(mocksubject(0), 0)
        le.add(t)

        le.recalculate.assert_called_once_with()
예제 #4
0
    def test_recalculate_1(self):
        le = ULedger(0)
        t0 = UTransaction(mocksubject(0, 0), 0)
        t1 = UTransaction(mocksubject(1, 1), 0)
        t2 = UTransaction(mocksubject(2, 1), 0)

        le.add(t0)
        le.add(t1)
        le.add(t2)

        assert le.recalculate() == (2 / 3, 1 / 4)
예제 #5
0
    def test_recalculate_2(self):
        le = ULedger(0)
        t0 = UTransaction(mocksubject(0, 1), 0)
        t1 = UTransaction(mocksubject(1, 1), 0)
        t2 = UTransaction(mocksubject(2, 1), 0)
        t3 = UTransaction(mocksubject(2, 1), 1)

        le.add(t0)
        le.add(t1)
        le.add(t2)
        le.add(t3)

        assert le.recalculate() == (1 / 2, 2 / 5)
예제 #6
0
    def test_recalculate_gamma(self):
        le = ULedger(0)
        t = [
            (0, 1, 0),
            (1, 1, 0),
            (2, 1, 0),
            (3, 1, 1),
            (4, 0, 0),
            (5, 0, 0),
            (6, 0, 0),
            (7, 0, 0),
        ]

        _ = [le.add(UTransaction(mocksubject(i, g), a)) for i, g, a in t]

        assert le.recalculate() == (9 / 14, 6 / 14)
예제 #7
0
 def test_add(self):
     le = ULedger(0)
     t = UTransaction(mocksubject(0), 0)
     le.add(t)
     assert t.gold is None
예제 #8
0
 def test_init(self):
     le = ULedger(17)
     assert le.id == 17
     assert type(le.no) is Counter
     assert type(le.yes) is Counter
     assert le._score == (0.5, 0.5)