Best Python code snippet using autotest_python
test_scoring.py
Source:test_scoring.py
...19 def test_mixed(self):20 a = np.array([1, 'a', 0, 1])21 b = np.array([1, 'b', 1, 1])22 self.assertEqual(accuracy_1d(a, b), 0.5)23 def test_unequal_len(self):24 a = np.array([1, 1, 0])25 b = np.array([1, 1, 1, 1])26 with self.assertRaises(ValueError) as context:27 accuracy_1d(a, b)28 msg = context.exception29 self.assertEqual(str(msg), "Input arrays must have same number"30 " of elements\n"31 "Got predictions.shape:"32 " (3,) and targets.shape: (4,)")33 def test_2d(self):34 a = np.array([[1, 1, 0, 0]])35 b = np.array([[1, 1, 1, 1]])36 with self.assertRaises(ValueError) as context:37 accuracy_1d(a, b)38 msg = context.exception39 self.assertEqual(str(msg), "Input arrays must have 1 dimension\n"40 "Got predictions.ndim: 2"41 " and targets.ndim: 2")42class TestAccuracy2D(unittest.TestCase):43 def test_binary(self):44 a = np.array([[1., 0., 0., 0.],45 [0., 1., 0., 0.],46 [0., 0., 0., 1.],47 [0., 0., 0., 1.]])48 b = np.array([[0., 0., 0., 1.],49 [0., 1., 0., 0.],50 [0., 0., 0., 1.],51 [0., 0., 0., 1.]])52 self.assertEqual(accuracy_2d(a, a), 1.0)53 self.assertEqual(accuracy_2d(a, b), 0.75)54 def test_unequal_len(self):55 a = np.array([[1., 0., 0., 0.],56 [0., 1., 0., 0.],57 [0., 0., 0., 1.]])58 b = np.array([[0., 0., 0., 1.],59 [0., 1., 0., 0.],60 [0., 0., 0., 1.],61 [0., 0., 0., 1.]])62 with self.assertRaises(ValueError) as context:63 accuracy_2d(a, b)64 msg = context.exception65 self.assertEqual(str(msg), "Input arrays must have same number"66 " of elements\n"67 "Got predictions.shape:"68 " (3, 4) and targets.shape: (4, 4)")...
zip_test.py
Source:zip_test.py
...21 l = list(zipped)22 assert l[0] == (1,)23 assert l[1] == (2,)24 assert l[2] == (3,)25def test_unequal_len():26 l = list(zip(range(3), range(100)))27 assert len(l) == 328 assert l[0] == (0, 0)29 assert l[1] == (1, 1)30 assert l[2] == (2, 2)31def test_unzip():32 pairs = [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]33 numbers, letters = zip(*pairs)34 assert numbers == (1, 2, 3, 4)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!