def test_bulk_operations(): say_test("test_bulk_operations") tc = TestCase() lst = LinkedList() lst2 = LinkedList() lst3 = lst + lst2 tc.assertIsInstance(lst3, LinkedList) tc.assertEqual(0, len(lst3)) import random data = [random.randrange(1000) for _ in range(50)] data2 = [random.randrange(1000) for _ in range(50)] for d in data: lst.append(d) for d in data2: lst2.append(d) lst3 = lst + lst2 tc.assertEqual(100, len(lst3)) data3 = data + data2 for i in range(len(data3)): tc.assertEqual(data3[i], lst3[i]) lst.clear() tc.assertEqual(0, len(lst)) with tc.assertRaises(IndexError): lst[0] for d in data: lst.append(d) lst2 = lst.copy() tc.assertIsNot(lst, lst2) tc.assertIsNot(lst.head.next, lst2.head.next) for i in range(len(data)): tc.assertEqual(lst[i], lst2[i]) tc.assertEqual(lst, lst2) lst.clear() lst.extend(range(10)) lst.extend(range(10, 0, -1)) lst.extend(data.copy()) tc.assertEqual(70, len(lst)) data = list(range(10)) + list(range(10, 0, -1)) + data for i in range(len(data)): tc.assertEqual(data[i], lst[i])
def ValidateMetrics(test: unittest.TestCase, pipeline_result: beam.runners.runner.PipelineResult, telemetry_descriptors: List[Text], logical_format: Text, physical_format: Text): all_metrics = pipeline_result.metrics() maintained_metrics = all_metrics.query( beam.metrics.metric.MetricsFilter().with_namespace( "tfx." + ".".join(telemetry_descriptors + ["io"]))) test.assertIsNot(maintained_metrics, None) counters = maintained_metrics[beam.metrics.metric.MetricResults.COUNTERS] test.assertTrue(counters) distributions = maintained_metrics[ beam.metrics.metric.MetricResults.DISTRIBUTIONS] test.assertTrue(distributions) for m in counters + distributions: test.assertTrue( m.key.metric.name.startswith( "LogicalFormat[%s]-PhysicalFormat[%s]-" % (logical_format, physical_format)))
def test_case_6(): test_log("testing bulk operations") tc = TestCase() lst = ArrayList() lst2 = ArrayList() lst3 = lst + lst2 tc.assertIsInstance(lst3, ArrayList) tc.assertEqual([], arrayListToList(lst3)) data = [random.randrange(1000) for _ in range(50)] data2 = [random.randrange(1000) for _ in range(50)] lst.data = ConstrainedList.create(data) lst.len = len(lst.data) lst2.data = ConstrainedList.create(data2) lst2.len = len(lst.data) lst3 = lst + lst2 tc.assertEqual(100, len(lst3)) tc.assertEqual(data + data2, arrayListToList(lst3)) lst.clear() tc.assertEqual([], arrayListToList(lst)) lst.data = ConstrainedList.create( [random.randrange(1000) for _ in range(50)]) lst2 = lst.copy() tc.assertIsNot(lst, lst2) tc.assertIsNot(lst.data, lst2.data) tc.assertEqual(arrayListToList(lst), arrayListToList(lst2)) lst.clear() lst.extend(range(10)) lst.extend(range(10, 0, -1)) lst.extend(data.copy()) tc.assertEqual(70, len(lst)) tc.assertEqual( list(range(10)) + list(range(10, 0, -1)) + data, arrayListToList(lst)) suc()
import random data = [random.randrange(1000) for _ in range(50)] data2 = [random.randrange(1000) for _ in range(50)] lst.data = ConstrainedList(data) lst2.data = ConstrainedList(data2) lst3 = lst + lst2 tc.assertEqual(100, len(lst3)) tc.assertEqual(data + data2, lst3.data._as_list()) lst.clear() tc.assertEqual([], lst.data._as_list()) lst.data = ConstrainedList([random.randrange(1000) for _ in range(50)]) lst2 = lst.copy() tc.assertIsNot(lst, lst2) tc.assertIsNot(lst.data, lst2.data) tc.assertEqual(lst.data._as_list(), lst2.data._as_list()) lst.clear() lst.extend(range(10)) lst.extend(range(10,0,-1)) lst.extend(data.copy()) tc.assertEqual(70, len(lst)) tc.assertEqual(list(range(10))+list(range(10,0,-1))+data, lst.data._as_list()) # In[194]: # (2 points) test iteration
def assert_is_not_null(put: unittest.TestCase, actual: sut.TokenStream): put.assertFalse(actual.is_null, 'is null') put.assertIsNot(LookAheadState.NULL, actual.look_ahead_state, 'look ahead state')
lst2.append(d) lst3 = lst + lst2 tc.assertEqual(100, len(lst3)) data3 = data + data2 for i in range(len(data3)): tc.assertEqual(data3[i], lst3[i]) lst.clear() tc.assertEqual(0, len(lst)) with tc.assertRaises(IndexError): lst[0] for d in data: lst.append(d) lst2 = lst.copy() tc.assertIsNot(lst, lst2) tc.assertIsNot(lst.head.next, lst2.head.next) for i in range(len(data)): tc.assertEqual(lst[i], lst2[i]) tc.assertEqual(lst, lst2) lst.clear() lst.extend(range(10)) lst.extend(range(10, 0, -1)) lst.extend(data.copy()) tc.assertEqual(70, len(lst)) data = list(range(10)) + list(range(10, 0, -1)) + data for i in range(len(data)): tc.assertEqual(data[i], lst[i])
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): put.assertIsNot(self.expected, value, message_builder.apply(self.message))