From bc54871dac7ef10102edecf91a747d6595a4640f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 9 Jan 2013 17:04:10 +0100 Subject: o Adding basic build list in the front page application. --- .../java/io/trygvis/esper/testing/UuidTest.java | 66 +++++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/io/trygvis/esper/testing/UuidTest.java b/src/test/java/io/trygvis/esper/testing/UuidTest.java index 1efec73..8d36177 100755 --- a/src/test/java/io/trygvis/esper/testing/UuidTest.java +++ b/src/test/java/io/trygvis/esper/testing/UuidTest.java @@ -10,6 +10,8 @@ import static org.junit.Assert.*; public class UuidTest { + boolean silent = System.getProperty("idea.launcher") != null; + @Test public void testToString() { String s = "fedcba98-7654-3210-fedc-ba9876543210"; @@ -33,6 +35,44 @@ public class UuidTest { assertEquals(uuid.toUuidString(), Uuid.fromString(uuid.toStringBase64()).toUuidString()); } + @Test + public void test2_() { + UUID uuid = UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"); + + String base64 = new Uuid(uuid).toStringBase64(); + + assertEquals(toBase64(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()), base64); + + assertEquals(uuid, Uuid.parseBase64(base64).toUUID()); + } + + @Test + public void test3() { + Uuid uuid = Uuid.fromString("3f4fc3bc-967a-40a7-9fc2-46398d35fa25"); + + UUID x = UUID.fromString(uuid.toUuidString()); + String s = toBase64(x.getMostSignificantBits(), x.getLeastSignificantBits()); + System.out.println(s); + + System.out.println("uuid.toUuidString() = " + uuid.toUuidString()); + System.out.println("uuid.toStringBase64() = " + uuid.toStringBase64()); + + assertEquals(uuid, Uuid.fromString(uuid.toUuidString())); + + assertEquals(uuid.toUuidString(), Uuid.fromString(uuid.toStringBase64()).toUuidString()); + } + + @Test + public void test4() { + Uuid uuid = Uuid.fromString("c541ff9e-e0a6-4eda-8eea-3f19e5ef893a"); + + System.out.println(System.getProperties()); + + assertEquals(uuid, Uuid.fromString(uuid.toUuidString())); + + assertEquals(uuid.toUuidString(), Uuid.fromString(uuid.toStringBase64()).toUuidString()); + } + @Test public void random() { Random random = new Random(0); @@ -40,9 +80,11 @@ public class UuidTest { for(int i = 0; i < 100; i++) { long most = random.nextLong(); long least = random.nextLong(); - System.out.println(format("i=%2d, most=%08x, least=%08x", i, most, least)); + if(!silent) + System.out.println(format("i=%2d, most=%08x, least=%08x", i, most, least)); UUID s = new UUID(most, least); + System.out.println("s = " + s); Uuid uuid = Uuid.fromString(s.toString()); assertEquals(s.toString(), uuid.toUuidString()); @@ -52,16 +94,34 @@ public class UuidTest { private String toBase64(long most, long least) { String x = StringUtils.leftPad(Long.toBinaryString(most), 64, '0') + StringUtils.leftPad(Long.toBinaryString(least), 64, '0'); - System.out.println(x); + if(!silent) + System.out.println(x); String r = ""; for (int i = 0; i < 22; i++) { int end = Math.min((i + 1) * 6, x.length()); String y = x.substring(i * 6, end); int number = Integer.parseInt(y, 2); - System.out.println(format("% 4d % 4d binary=%8s, dec=%2d %c", i, end, y, number, Uuid.alphabet[number])); + if(!silent) + System.out.println(format("% 4d % 4d binary=%8s, dec=%2d %c", i, end, y, number, Uuid.alphabet[number])); r += Uuid.alphabet[number]; } return r; } + + /* + private UUID fromBase64(String s) { + assertEquals(22, s.length()); + + int shift = 60; + long most = 0, least = 0; + + for (int i = 0; i < 22; i += 6) { + String x = s.substring(i, Math.min(s.length(), i + 6)); + System.out.println("x = " + x); + Integer.parseInt(x); + + } + } + */ } -- cgit v1.2.3