def test_str_repr(self): x = quakelib.Vec3(1, 2, 3) y = quakelib.Vec2(1, 2) xp = eval(repr(x)) yp = eval(repr(y)) self.assertEqual(x, xp) self.assertEqual(y, yp)
def testGreenSymmetricDGDV(self): source_dim = quakelib.Vec3(1, 1, 1) for x in range(-2, 8): for y in range(-2, 8): # Set up the test location and mirror location z = 0 xloc = source_dim[0] / 2.0 + 2**x yloc = 2**y zloc = -z orig_loc_dg = quakelib.Vec2(xloc, yloc) orig_loc_dv = quakelib.Vec3(xloc, yloc, zloc) xloc = source_dim[0] / 2.0 - 2**x yloc = -2**y mirror_loc_dg = quakelib.Vec2(xloc, yloc) mirror_loc_dv = quakelib.Vec3(xloc, yloc, zloc) # Calculate dudz orig_dg = self.ok.calc_dg(orig_loc_dg, source_dim[2], self.dip_rad, source_dim[0], source_dim[1], self.slip_vec[0], self.slip_vec[1], self.slip_vec[2], 1, 1) mirror_dg = self.ok.calc_dg(mirror_loc_dg, source_dim[2], self.dip_rad, source_dim[0], source_dim[1], self.slip_vec[0], self.slip_vec[1], self.slip_vec[2], 1, 1) orig_dv = self.ok.calc_dV(orig_loc_dv, source_dim[2], self.dip_rad, source_dim[0], source_dim[1], self.slip_vec[0], self.slip_vec[1], self.slip_vec[2], 1, 1) mirror_dv = self.ok.calc_dV(mirror_loc_dv, source_dim[2], self.dip_rad, source_dim[0], source_dim[1], self.slip_vec[0], self.slip_vec[1], self.slip_vec[2], 1, 1) abs_err_dg = abs(orig_dg + mirror_dg) abs_err_dv = abs(orig_dv + mirror_dv) self.assertTrue(abs_err_dg < self.mag_tol) self.assertTrue(abs_err_dv < self.mag_tol)
def test_index_error(self): x = quakelib.Vec3(1, 2, 3) y = quakelib.Vec2(1, 2) with self.assertRaises(OverflowError): x[-1] with self.assertRaises(OverflowError): x[-1] = 0 with self.assertRaises(IndexError): x[3] with self.assertRaises(IndexError): x[3] = 0 with self.assertRaises(OverflowError): y[-1] with self.assertRaises(OverflowError): y[-1] = 0 with self.assertRaises(IndexError): y[2] with self.assertRaises(IndexError): y[2] = 0
def test_cross_prod(self): self.assertEqual(self.x.cross(self.y), quakelib.Vec3()) self.assertEqual(self.y.cross(self.x), quakelib.Vec3()) self.assertEqual(self.x.cross(self.z), quakelib.Vec3(-5, -5, 5)) self.assertRaises(ValueError, quakelib.Vec2().cross, (quakelib.Vec2()))