def test_id_less(): id1 = c4.Identify("1") # c42yrSHMvUcscrQBssLhrRE28YpGUv9Gf95uH8KnwTiBv4odDbVqNnCYFs3xpsLrgVZfHebSaQQsvxgDGmw5CX1fVy id2 = c4.Identify("2") # c42i2hTBA9Ej4nqEo9iUy3pJRRE53KAH9RwwMSWjmfaQN7LxCymVz1zL9hEjqeFYzxtxXz2wRK7CBtt71AFkRfHodu if id1.less(id2) != False: eprint("expected %q to be less than %q", id2, id1) return False return True
def test_identification(): for test in test_vectors : c4id = c4.Identify(test) if c4id.string() != test_vector_ids[0][i]: eprint("IDs don't match, got %q expected %q", c4id.string(), test_vector_ids[0][i]) return False return True
def test_nil_id(): # ID of nothing constant nilid = c4.Identify("") if nilid.string() != "c459dsjfscH38cYeXXYogktxf4Cd9ibshE3BHUo6a58hBXmRQdZrAkZzsWcbWtDg5oQstpDuni4Hirj75GEmTc1sFT": eprint("IDs don't match, got %q, expcted %q", nilid.string(), "c459dsjfscH38cYeXXYogktxf4Cd9ibshE3BHUo6a58hBXmRQdZrAkZzsWcbWtDg5oQstpDuni4Hirj75GEmTc1sFT") return False return True
def test_id_cmp(): id1 = c4.Identify("1") # c42yrSHMvUcscrQBssLhrRE28YpGUv9Gf95uH8KnwTiBv4odDbVqNnCYFs3xpsLrgVZfHebSaQQsvxgDGmw5CX1fVy id2 = c4.Identify("2") # c42i2hTBA9Ej4nqEo9iUy3pJRRE53KAH9RwwMSWjmfaQN7LxCymVz1zL9hEjqeFYzxtxXz2wRK7CBtt71AFkRfHodu # is.Equal(id1.Cmp(id2), 1) if id1.Cmp(id2) != 1: eprint("Incorrect comparison between %q, %q", id1, id2) return False if id2.Cmp(id1) != -1: eprint("Incorrect comparison between %q, %q", id2, id1) return False if id1.Cmp(id1) != 0: eprint("Incorrect comparison between %q, %q", id1, id1) return False return True
def TestCompareIDs(): tests = [ { "id_a": c4.Identify(strings.NewReader("Test string")), "id_b": c4.Identify(strings.NewReader("Test string")), "exp": 0 }, { "id_a": c4.Identify(strings.NewReader("Test string A")), "id_b": c4.Identify(strings.NewReader("Test string B")), "exp": -1 }, { "id_a": c4.Identify(strings.NewReader("Test string B")), "id_b": c4.Identify(strings.NewReader("Test string A")), "exp": 1 }, { "id_a": c4.Identify(strings.NewReader("Test string")), "id_b": id, "exp": -1 } ] for test in tests: if test["id_a"].Cmp(test["id_b"]) != test["exp"]: eprint("Incorrect comparison between %q, %q", test["id_a"], test["id_b"]) return False
def test_encoding(): tests = [ { 'in': "", 'exp': "c459dsjfscH38cYeXXYogktxf4Cd9ibshE3BHUo6a58hBXmRQdZrAkZzsWcbWtDg5oQstpDuni4Hirj75GEmTc1sFT" } ] for test in tests: actual = c4.Identify(test['in']) if actual.string() != test['exp']: eprint("IDs don't match, got ", actual, " expected ", test["exp"]) return False return True
def TestDigestSum(): test_data = [] for s in test_vectors: dig = c4.Identify(s) id, err = c4.parse(test_vector_ids[0][i]) if err != nil: eprint("unexpected error %q", err) if id.string() != dig.string(): eprint("IDs don't match, got %q expected %q", id, dig) if id.string() != test_vector_ids[0][i]: eprint("IDs don't match, got %q expected %q", id.string(), test_vector_ids[0][i]) test_data = append(test_data, testDataType{s, id, test_vector_ids[0][i]})
def test_parse(): tests = [ { "in": "c43ucjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9D", "err": None, "exp": "This is a pretend asset file, for testing asset id generation.\n" }, { "in": "c430cjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9D", "err": "invalid character at 3", "exp": "" }, { "in": "c430cjRutKqZSCrW43QGU1uwRZTGoVD7A7kPHKQ1z4X1Ge8mhW4Q1gk48Ld8VFpprQBfUC8JNvHYVgq453hCFrgf9", "err": "is not 90 characters long", "exp": "" } ] i = 0 for test in tests: id, err = c4.parse(test["in"]) if test["err"] is not None: if not err: eprint("Expected error but got none") return False elif err != test["err"]: eprint("incorrect error got ", err, " expected ", test["err"]) return False continue elif err is not None: eprint("Unexpected error ", err) return False expectedID = c4.Identify(test["exp"]) if expectedID != id: eprint("IDs don't match, got ", _stringOf(id), ", expcted ", _stringOf(expectedID)) return False return True