예제 #1
0
 def test_get_buffer_has_right_size(self):
     bm = BufferManager()
     sg1 = lambda t, b: 2 * t * b
     sg2 = lambda t, b: 3 * t * b
     view_factory = lambda x, t, b: x
     bm.add({'foo1': (sg1, view_factory), 'foo2': (sg2, view_factory)}, {})
     bm.set_dimensions(1, 1)
     self.assertEqual(len(bm.get_source_view('foo1')), 2)
     self.assertEqual(len(bm.get_source_view('foo2')), 3)
     bm.set_dimensions(2, 3)
     self.assertEqual(len(bm.get_source_view('foo1')), 12)
     self.assertEqual(len(bm.get_source_view('foo2')), 18)
예제 #2
0
 def test_calculate_size_with_one_sink_and_one_source_size_getter(self):
     bm = BufferManager()
     size_getter = lambda t, b: 10 * t + b
     view_factory = lambda x, t, b: x
     bm.add({'source': (size_getter, view_factory)},
            {'sink': (size_getter, view_factory)})
     bm.set_dimensions(1, 1)
     self.assertEqual(bm.calculate_size(), 11)
     bm.set_dimensions(10, 5)
     self.assertEqual(bm.calculate_size(), 105)
     bm.set_dimensions(2, 3)
     self.assertEqual(bm.calculate_size(), 23)
예제 #3
0
 def test_calculate_size_with_multiple_size_getters(self):
     bm = BufferManager()
     sg1 = lambda t, b: 10 * t + b
     sg2 = lambda t, b: 1000 * t + 100 * b
     sg3 = lambda t, b: 100000 * t + 10000 * b
     view_factory = lambda x, t, b: x
     bm.add({'foo1': (sg1, view_factory)}, {})
     bm.add({'foo2': (sg2, view_factory)}, {})
     bm.add({'foo3': (sg3, view_factory)}, {})
     bm.set_dimensions(1, 1)
     self.assertEqual(bm.calculate_size(), 111111)
     bm.set_dimensions(2, 3)
     self.assertEqual(bm.calculate_size(), 232323)
예제 #4
0
 def test_no_source_raises(self):
     bm = BufferManager()
     size_getter = lambda t, b: 10 * t + b
     view_factory = lambda x, t, b: x
     with self.assertRaises(AssertionError):
         bm.add({}, {'foo': (size_getter, view_factory)})