Created
December 4, 2017 18:04
-
-
Save Icaro-Lima/08621ff2d18b5babc226123e7c5d3e16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testTDG() { | |
Random rand = new Random(); | |
final int COUNT_TESTS = 1000; | |
final int MAX_OPERATIONS = 1000; | |
for (int t = 0; t < COUNT_TESTS; t++) { | |
int operations = rand.nextInt(MAX_OPERATIONS); | |
ArrayList<Integer> arrayList = new ArrayList<>(); | |
RecursiveSingleLinkedListImpl<Integer> linkedList = new RecursiveSingleLinkedListImpl<>(); | |
for (int i = 0; i < operations; i++) { | |
int ch = rand.nextInt(6); | |
if (ch == 0) { | |
Integer element = rand.nextInt(20); | |
arrayList.add(element); linkedList.insert(element); | |
} else if (ch == 1) { | |
Assert.assertEquals(arrayList.size(), linkedList.size()); | |
} else if (ch == 2) { | |
Assert.assertEquals(arrayList.isEmpty(), linkedList.isEmpty()); | |
} else if (ch == 3) { | |
Integer element = rand.nextInt(20); | |
int index = arrayList.indexOf(element); | |
if (index == -1) { | |
Assert.assertNull(linkedList.search(element)); | |
} else { | |
Assert.assertEquals(arrayList.get(index), linkedList.search(element)); | |
} | |
} else if (ch == 4) { | |
Integer element = rand.nextInt(20); | |
arrayList.remove(element); | |
linkedList.remove(element); | |
} else { | |
Assert.assertArrayEquals(arrayList.toArray(), linkedList.toArray()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment