我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用test.test()。
def parse_args(): """Parse input arguments.""" parser = argparse.ArgumentParser(description='Deep360Pilot') parser.add_argument('--opt', dest='opt_method', help='[Adam, Adadelta, RMSProp]', default='Adam') parser.add_argument('--root', dest='root_path', help='root path of data', default='./') parser.add_argument('--data', dest='data_path', help='data path of data', default='./data/') parser.add_argument('--mode', dest='mode', help='[train, test, vid, pred]', required=True) parser.add_argument('--model', dest='model_path', help='model path to load') parser.add_argument('--gpu', dest='gpu', help='Choose which gpu to use', default='0') parser.add_argument('-n', '--name', dest='video_name', help='youtube_id + _ + part') parser.add_argument('-d', '--domain', dest='domain', help='skate, skiing, ...', required=True) parser.add_argument('-l', '--lambda', dest='lam', help='movement tradeoff lambda, the higher the smoother.', type=float, required=True) parser.add_argument('-b', '--boxnum', dest='boxnum', help='boxes number, Use integer, [8, 16, 32]', type=int, required=True) parser.add_argument('-p', '--phase', dest='phase', help='phase [classify, regress]', required=True) parser.add_argument('-s', '--save', dest='save', help='save images for debug', default=False) group = parser.add_mutually_exclusive_group() group.add_argument('--debug', dest='debug', help='Start debug mode or not', action='store_true') args = parser.parse_args() return args, parser
def test_reps(): x = (0, 1) x2 = (0, 2) y = (2, 0) y2 = (4, 0) xy = (2, 1) yx = (2, p1271 - 1) z = (3, 4) z2 = (6, 8) ta = (5, 0) tb = (1, 6) t = (5, 30) td2 = GFp2.mul((2,0), GFp2.mul(d, t)) r1 = (x, y, z, ta, tb) r2 = (xy, yx, z2, td2) r3 = (xy, yx, z, t) r4 = (x2, y2, z2) test.test("R1toR2", R1toR2(r1), r2) test.test("R1toR3", R1toR3(r1), r3) test.test("R2toR4", R2toR4(r2), r4)
def test_mul(label, mul): TEST_LOOPS = 1000 scalar = [0x3AD457AB55456230, 0x3A8B3C2C6FD86E0C, 0x7E38F7C9CFBB9166, 0x0028FD6CBDA458F0] coeff = range(TEST_LOOPS) for i in range(TEST_LOOPS): scalar[1] = scalar[2] scalar[2] += scalar[0] scalar[2] &= 0xffffffffffffffff coeff[i] = (scalar[0] << (0 * 64)) + (scalar[1] << (1 * 64)) + \ (scalar[2] << (2 * 64)) + (scalar[3] << (3 * 64)) A = AffineToR1(Gx, Gy) for i in range(TEST_LOOPS): A = mul(coeff[i], A) mulP = ((0x257C122BBFC94A1BDFD2B477BD494BEF, 0x469BF80CB5B11F01769593547237C459), (0x0901B3817C0E936C281C5067996F3344, 0x570B948EACACE2104FE8C429915F1245)) test.testpt(label, A, mulP)
def test_endo(): TEST_LOOPS = 1000 # Test phi endomorphism P = AffineToR1(Gx, Gy) for i in range(TEST_LOOPS): P = phi(P) phiP = ((0x5550AAB9E7A620EED5B5A3061287DB16, 0x3E61EBB9A1CB0210EC321E6CF33610FC), (0x5474BF8EC55603AE7E2851D5A8E83FB9, 0x5476093DBF8BF6BFA5077613491788D5)) test.testpt("phi", P, phiP) # Test psi endomorphism P = AffineToR1(Gx, Gy) for i in range(TEST_LOOPS): P = psi(P) psiP = ((0x75AF54EDB41A2B93D8F3C8C24A2BC7E2, 0x065249F9EDE0C7984DE2466701F009A9), (0x06DBB85BFFB7C21E1C6E119ADD608104, 0x060A30903424BF13FD234D6C4CFA3EC1)) test.testpt("psi", P, psiP)
def test_dh(): a = '77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a'.decode('hex') KA = '8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a'.decode('hex') b = '5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb'.decode('hex') KB = 'de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f'.decode('hex') K = '4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742'.decode('hex') nine = '0900000000000000000000000000000000000000000000000000000000000000'.decode('hex') KAt = x25519(a, nine) KBt = x25519(b, nine) KABt = x25519(a, x25519(b, nine)) KBAt = x25519(b, x25519(a, nine)) test.test('DH-KA', KAt, KA) test.test('DH-KB', KBt, KB) test.test('DH-KAB', KABt, K) test.test('DH-KBA', KBAt, K)
def main(args): if args.test == False: train(args) else: test(args)
def run(self): if test is not None and test.test is not None: assert test.test() == True, "Automated tests failed!" print("notice all tests passed: OK!") else: print("notice automated tests skipped!") build.run(self)
def run(self): if test is not None and test.test is not None: assert test.test() == True, "Automated tests failed!" print("notice all tests passed: OK!") else: print("notice automated tests skipped!")
def test_GFp(): inv13 = GFp.inv(13) test.test("inv-1271", GFp.mul(inv13, 13), 1) invsqrt13 = GFp.invsqrt(13) test.test("invsqrt-1271", GFp.mul(13, GFp.sqr(invsqrt13)), 1)
def test_GFp2(): one = (1,0) i = (0,1) x23 = (2, 3) x57 = (5, 7) test.test("1+i", GFp2.add(one, i), (1, 1)) test.test("1*i", GFp2.mul(one, i), (0, 1)) test.test("i*i", GFp2.mul(i, i), (p1271 - 1, 0)) test.test("add", GFp2.add(x23, x57), (7, 10)) test.test("sub-pos", GFp2.sub(x57, x23), (3, 4)) test.test("sub-neg", GFp2.sub(x23, x57), (p1271 - 3, p1271 - 4)) test.test("mul", GFp2.mul(x23, x57), (p1271 - 11, 29)) test.test("sqr", GFp2.sqr(x23), (p1271 - 5, 12)) x23c = GFp2.conj(x23) x23i = GFp2.inv(x23) x23is = GFp2.invsqrt(x23) test.test("conj", x23c, (2, GFp.neg(3))) test.test("inv-1271-2", GFp2.mul(x23, x23i), one) test.test("invsqrt-1271-2", GFp2.mul(x23, GFp2.sqr(x23is)), one) select1 = GFp2.select(1, x23, x57) select0 = GFp2.select(0, x23, x57) test.test("select(1)", select1, x23) test.test("select(0)", select0, x57)
def test_GFp25519(): inv13 = GFp25519.inv(13) test.test("inv-25519", GFp25519.mul(inv13, 13), 1)
def DH_endo(m, P, table=None): return DH_core(m, P, MUL_endo, table=table) ########## Self test for correctness ########## ########## (cases are from FourQlib) ##########
def test_definitions(): test.test("0-on-curve", PointOnCurve((Ox, Oy)), True) test.test("G-on-curve", PointOnCurve((Gx, Gy)), True)
def test_core(): TEST_LOOPS = 1000 # Test doubling A = (Gx, Gy, GFp2.one) for i in range(TEST_LOOPS): A = DBL(A)[:3] doubleP = ((0x2C3FD8822C82270FC9099C54855859D6, 0x4DA5B9E83AA7A1B2A7B3F6E2043E8E68), (0x2001EB3A576883963EE089F0EB49AA14, 0x0FFDB0D761421F501FEE5617A7E954CD)) test.testpt("double", A, doubleP) # Test that the neutral element is neutral G = AffineToR1(Gx, Gy) O = AffineToR1(Ox, Oy) PP = ADD(G, R1toR2(O)) test.testpt("neutral-r", PP, G) PP = ADD(O, R1toR2(G)) test.testpt("neutral-l", PP, G) # Test point doubling by addition P = G for i in range(TEST_LOOPS): Q = R1toR2(P) P = ADD(P, Q) test.testpt("double-add", P, doubleP) # Test repeated addition of the same point P = G Q = R1toR2(P) P = DBL(P[:3]) for i in range(TEST_LOOPS): P = ADD(P, Q) P1000 = ((0x3E243958590C4D906480B1EF0A151DB0, 0x5327AF7D84238CD0AA270F644A65D473), (0x3EF69A49CB7E02375E06003D73C43EB1, 0x293EB1E26DD23B4E4E752648AC2EF0AB)) test.testpt("addition", P, P1000)
def test_mul_windowed(): # Test multiplication by one and two A = AffineToR1(Gx, Gy) B = MUL_windowed(1, A) test.testpt("mul-windowed-*1", B, A) A2 = DBL(A) B2 = MUL_windowed(2, A) test.testpt("mul-windowed-*2", B2, A2) # Test multiply over several iterations test_mul("mul-windowed", MUL_windowed) # Test fixed-based multiply T = table_windowed(A) B = MUL_windowed(1, A, table=T) B2 = MUL_windowed(2, A, table=T) test.testpt("mul-windowed-fixed-*1", B, A) test.testpt("mul-windowed-fixed-*2", B2, A2) failed = 0 for i in range(10): m = getrandbits(256) B1 = MUL_windowed(m, A, table=T) B2 = MUL_windowed(m, A) if B1 != B2: failed += 1 if failed == 0: print "[PASS] mul-windowed-fixed-rand" else: print "[FAIL] mul-windowed-fixed-rand"
def test_mul_endo(): # Test multiplication by one and two A = AffineToR1(Gx, Gy) B = MUL_endo(1, A) test.testpt("mul-endo-*1", B, A) A2 = DBL(A) B2 = MUL_endo(2, A) test.testpt("mul-endo-*2", B2, A2) # Test multiply over several iterations test_mul("mul-endo", MUL_endo) # Test fixed-based multiply T = table_endo(A) B = MUL_endo(1, A, table=T) B2 = MUL_endo(2, A, table=T) test.testpt("mul-endo-fixed-*1", B, A) test.testpt("mul-endo-fixed-*2", B2, A2) failed = 0 for i in range(10): m = getrandbits(256) B1 = MUL_endo(m, A, table=T) B2 = MUL_endo(m, A) if B1 != B2: failed += 1 if failed == 0: print "[PASS] mul-windowed-fixed-rand" else: print "[FAIL] mul-windowed-fixed-rand"
def x25519(k, u): kn = decodeScalar(k) un = decodeUCoord(u) return encodeUCoord(x25519_inner(kn, un)) ########## Self test for correctness ########## ########## (cases are from RFC 7748) ##########
def test_x25519(): k0 = 'a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4'.decode('hex') u0 = 'e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c'.decode('hex') r0 = 'c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552'.decode('hex') rp = x25519(k0, u0) test.test('rfc-0', rp, r0) k1 = '4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d'.decode('hex') u1 = 'e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493'.decode('hex') r1 = '95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957'.decode('hex') test.test('rfc-1', x25519(k1, u1), r1) k = '0900000000000000000000000000000000000000000000000000000000000000'.decode('hex') u = '0900000000000000000000000000000000000000000000000000000000000000'.decode('hex') k1i = '422c8e7a6227d7bca1350b3e2bb7279f7897b87bb6854b783c60e80311ae3079'.decode('hex') k1k = '684cf59ba83309552800ef566f2f4d3c1c3887c49360e3875f2eb94d99532c51'.decode('hex') # XXX: Not currently tested k1m = '7c3911e0ab2586fd864497297e575e6f3bc601c0883c30df5f4dd2d24f665424'.decode('hex') TEST_LOOPS = 1001 for i in range(TEST_LOOPS): r = x25519(k, u) u = k k = r if i == 0: test.test("rfc-iter-1", k, k1i) elif i == 999: test.test("rfc-iter-1k", k, k1k) elif i == 999999: # XXX: Not currently tested test.test("rfc-iter-1m", k, k1m)