示例#1
0
    def test_sum_property(self):
        fifo = FIFORunningSum(3)

        self.assertEqual(fifo.sum, 0)

        with self.assertRaises(AttributeError):
            fifo.sum = 5
示例#2
0
    def test_len(self):
        fifo = FIFORunningSum(8)

        self.assertEqual(len(fifo), 0)

        fifo.append(1.0)
        self.assertEqual(len(fifo), 1)

        self.assertEqual(fifo._buffer.maxlen, 8)
示例#3
0
    def test_logical_values(self):
        fifo = FIFORunningSum(3)

        fifo.append(True)
        fifo.append(False)
        fifo.append(True)

        self.assertEqual(fifo.sum, 2)
示例#4
0
    def test_fifo_reset(self):
        fifo = FIFORunningSum(3)

        fifo.append(1)
        fifo.append(2)
        fifo.append(3)

        fifo.reset()

        self.assertEqual(fifo.sum, 0)
        self.assertEqual(fifo._buffer.maxlen, 3)
        self.assertEqual(len(fifo), 0)
示例#5
0
    def test_append(self):
        fifo = FIFORunningSum(3)

        fifo.append(1)
        self.assertEqual(fifo.sum, 1)

        fifo.append(2)
        self.assertEqual(fifo.sum, 3)

        fifo.append(3)
        self.assertEqual(fifo.sum, 6)

        fifo.append(4)
        self.assertEqual(fifo.sum, 9)

        fifo.append(5)
        self.assertEqual(fifo.sum, 12)

        fifo.append(6)
        self.assertEqual(fifo.sum, 15)
示例#6
0
 def test_max_len(self):
     tester = FIFORunningSum(8)
     self.assertEqual(tester.maxlen, 8)
示例#7
0
    def test_create(self):
        tester = FIFORunningSum(3)

        self.assertEqual(tester._buffer.maxlen, 3)
        self.assertEqual(tester._sum, 0)