Skip to content

Commit

Permalink
Changes to tests for correctness and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
magdel committed Feb 16, 2024
1 parent cc56a6a commit 61a2b59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/test/java/com/fasterxml/uuid/UUIDComparatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,6 @@ public void testSortingMV7() throws Exception {
sortedUUID.sort(new UUIDComparator());
HashSet<UUID> unique = new HashSet<UUID>(count);

for (int i = 0; i < created.size(); i++) {
assertEquals("Error at: " + i, created.get(i), sortedUUID.get(i));
if (!unique.add(created.get(i))) {
System.out.println("Duplicate at: " + i);
}
}
}
public void testSortingRandomMV7() throws Exception {
final int count = 10000000;
Random entropy = new Random(0x666);
final TimeBasedEpochRandomGenerator generator = Generators.timeBasedEpochRandomGenerator(entropy);
List<UUID> created = new ArrayList<UUID>(count);
for (int i = 0; i < count; i++) {
created.add(generator.generate());
}
List<UUID> sortedUUID = new ArrayList<UUID>(created);
sortedUUID.sort(new UUIDComparator());
HashSet<UUID> unique = new HashSet<UUID>(count);

for (int i = 0; i < created.size(); i++) {
assertEquals("Error at: " + i, created.get(i), sortedUUID.get(i));
if (!unique.add(created.get(i))) {
Expand Down
21 changes: 15 additions & 6 deletions src/test/java/com/fasterxml/uuid/UUIDGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void testGenerateRandomBasedUUID()

// we need a instance to use
RandomBasedGenerator uuid_gen = Generators.randomBasedGenerator();

assertEquals(uuid_gen.getType(), UUIDType.RANDOM_BASED);

// for the random UUID generator, we will generate a bunch of
// random UUIDs
UUID uuid_array[] = new UUID[SIZE_OF_TEST_ARRAY];
Expand Down Expand Up @@ -154,7 +155,8 @@ public void testGenerateTimeBasedUUID()

// we need a instance to use
TimeBasedGenerator uuid_gen = Generators.timeBasedGenerator();

assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED);

// first check that given a number of calls to generateTimeBasedUUID,
// all returned UUIDs order after the last returned UUID
// we'll check this by generating the UUIDs into one array and sorting
Expand Down Expand Up @@ -203,7 +205,8 @@ public void testGenerateTimeBasedUUIDWithEthernetAddress()

// we need a instance to use
TimeBasedGenerator uuid_gen = Generators.timeBasedGenerator(ethernet_address);

assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED);

// check that given a number of calls to generateTimeBasedUUID,
// all returned UUIDs order after the last returned UUID
// we'll check this by generating the UUIDs into one array and sorting
Expand Down Expand Up @@ -262,6 +265,7 @@ public void testGenerateTimeBasedEpochUUID() throws Exception

// we need a instance to use
TimeBasedEpochGenerator uuid_gen = Generators.timeBasedEpochGenerator(entropy);
assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED_EPOCH);

// first check that given a number of calls to generateTimeBasedEpochUUID,
// all returned UUIDs order after the last returned UUID
Expand Down Expand Up @@ -314,6 +318,7 @@ public void testGenerateTimeBasedEpochRandomUUID() throws Exception
// we need a instance to use
TimeBasedEpochRandomGenerator uuid_gen = Generators.timeBasedEpochRandomGenerator(entropy);

assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED_EPOCH);
// first check that given a number of calls to generateTimeBasedEpochUUID,
// all returned UUIDs order after the last returned UUID
// we'll check this by generating the UUIDs into one array and sorting
Expand Down Expand Up @@ -394,7 +399,8 @@ public void testGenerateNameBasedUUIDNameSpaceAndName()

// we need a instance to use
NameBasedGenerator uuid_gen = Generators.nameBasedGenerator(NameBasedGenerator.NAMESPACE_URL);

assertEquals(uuid_gen.getType(), UUIDType.NAME_BASED_SHA1);

UUID uuid_array[] = new UUID[SIZE_OF_TEST_ARRAY];

// now create the array of uuids
Expand Down Expand Up @@ -478,6 +484,7 @@ public void testGenerateNameBasedUUIDNameSpaceNameAndMessageDigest()
// generateNameBasedUUID method

NameBasedGenerator uuid_gen = Generators.nameBasedGenerator(NameBasedGenerator.NAMESPACE_URL, MESSAGE_DIGEST);
assertEquals(uuid_gen.getType(), UUIDType.NAME_BASED_MD5);
UUID uuid_array[] = new UUID[SIZE_OF_TEST_ARRAY];

// now create the array of uuids
Expand Down Expand Up @@ -554,7 +561,8 @@ public void testGenerateTimeBasedReorderedUUID()

// we need a instance to use
TimeBasedReorderedGenerator uuid_gen = Generators.timeBasedReorderedGenerator();

assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED_REORDERED);

// first check that given a number of calls to generateTimeBasedReorderedUUID,
// all returned UUIDs order after the last returned UUID
// we'll check this by generating the UUIDs into one array and sorting
Expand Down Expand Up @@ -603,7 +611,8 @@ public void testGenerateTimeBasedReorderedUUIDWithEthernetAddress()

// we need a instance to use
TimeBasedReorderedGenerator uuid_gen = Generators.timeBasedReorderedGenerator(ethernet_address);

assertEquals(uuid_gen.getType(), UUIDType.TIME_BASED_REORDERED);

// check that given a number of calls to generateTimeBasedReorderedUUID,
// all returned UUIDs order after the last returned UUID
// we'll check this by generating the UUIDs into one array and sorting
Expand Down

0 comments on commit 61a2b59

Please sign in to comment.