コード例 #1
0
    def test_add_transaction_last(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)

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

        assert le.last == t1
コード例 #2
0
    def test_get_prior_middle(self):
        user = MagicMock()
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(0), 0)

        t1.left = t0
        t0.score = 15

        assert t1.get_prior() == 15
コード例 #3
0
    def test_change(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)

        le.add(t0)
        le.add(t1)
        le.clear_changes()

        le._change(0)
        assert le.first_change == t0
コード例 #4
0
    def test_recalculate_beginning(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)
        t2 = STransaction(mockuser(2), 0)

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

        le.recalculate()
        assert STransaction.calculate.call_count == 3
コード例 #5
0
    def test_add_transaction_links(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)

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

        assert t1.left == t0
        assert t0.right == t1

        assert t1.right is None
        assert t0.left is None
コード例 #6
0
    def test_recalculate_middle(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)
        t2 = STransaction(mockuser(2), 0)

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

        le.changed = [1]
        le.recalculate()
        assert STransaction.calculate.call_count == 2
コード例 #7
0
    def test_recalculate_propagates(self):
        def u(i, s):
            return mockuser(i, s)

        le = SLedger(0)
        t0 = STransaction(u(0, (3 / 4, 3 / 4)), 1)
        t1 = STransaction(u(1, (1 / 4, 1 / 4)), 1)

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

        le.recalculate()

        assert le.score - .12 < 1e-10
コード例 #8
0
    def test_commit_change(self):
        t = STransaction(mockuser(1), 0)
        t.notify(mockuser(15, (0.1, 0.9)))
        t.commit_change()

        assert t.change == (0.1, 0.9)
        assert t.user_score == (0.1, 0.9)
コード例 #9
0
    def test_update_first_change(self):
        le = SLedger(0)
        t0 = STransaction(mockuser(0), 0)
        t1 = STransaction(mockuser(1), 0)
        t2 = STransaction(mockuser(2), 0)

        t1.notify = MagicMock()

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

        le.clear_changes()
        le.update(1)

        print(le.changed)
        assert le.first_change == t1
コード例 #10
0
    def test_init(self):
        t = STransaction(mockuser(0), 0)

        assert t.id == 0
        assert t.user_score == (0.5, 0.5)
        assert t.change == (0.5, 0.5)
        assert t.annotation == 0
        assert t.score is None

        assert t.left is None
        assert t.right is None
コード例 #11
0
    def test_recalculate_real(self):
        def u(i):
            return mockuser(i, score=(.25, .25))

        le = SLedger(0)
        for x in range(10):
            le.add(STransaction(u(x), 0))

        score = le.recalculate()
        print(score)
        assert score - 0.9998785824 < 1e-6
コード例 #12
0
    def test_calculate_nocommit(self):
        t = STransaction(mockuser(1), 0)
        t.notify(mockuser(15, (0.1, 0.9)))

        assert t.calculate(.12) == .12
コード例 #13
0
    def test_get_prior_first(self):
        t = STransaction(mocksubject(0), 0)

        assert t.get_prior() == 0.12
コード例 #14
0
    def test_add_legacy_nocalculate(self, mock):
        le = SLedger(0)
        t = STransaction(mockuser(0), 0)
        le.add(t)

        assert mock.call_count == 0
コード例 #15
0
    def test_calculate_1(self):
        user = mockuser(0, (.25, .8))

        t = STransaction(user, 1)
        assert t.calculate(.12) - .096 / .756 < 1e-10
コード例 #16
0
 def test_calculate_0(self):
     t = STransaction(mockuser(0, (.25, .8)), 0)
     assert t.calculate(.12) - .024 / .244 < 1e-10
コード例 #17
0
    def test_add_legacy_callscalculate(self, mock):
        le = SLedger(0)
        t = STransaction(mockuser(0), 0)
        le.add(t)

        mock.assert_called_once_with()