class TestSlidingWindowReservoir(TestCase): def setUp(self): self.res = SlidingWindowReservoir(15) def test_add_15_elements(self): for i in range(15): self.res.update(i) self.assertEqual(len(self.res), 15) def test_add_30_elements(self): for i in range(30): self.res.update(i) self.assertEqual(len(self.res), 30) self.assertEqual(len(self.res._res), 15) self.assertEqual(self.res._res, list(range(15, 30))) @patch('caliper.reservoir.Snapshot') def test_snapshot_receives_all_data(self, Snapshot): for i in range(15): self.res.update(i) snap = self.res.snapshot() Snapshot.assert_called_once_with(list(range(15))) @patch('caliper.reservoir.Snapshot') def test_snapshot_receives_most_recent_data(self, Snapshot): for i in range(30): self.res.update(i) snap = self.res.snapshot() Snapshot.assert_called_once_with(list(range(15, 30)))
def setUp(self): self.res = SlidingWindowReservoir(15)