Last active
December 12, 2017 01:25
-
-
Save Icaro-Lima/4fc983b6afffb2ea78dbb8c10b0c1a9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
| // Configurar aqui! | |
| final int TESTS_COUNT = 10000; | |
| final int OPERATIONS_COUNT = 1000; | |
| final int MAX_SIZE_INCLUSIVE = 31; | |
| final int MAX_ELEMENT_VALUE = 27; // [0, X). | |
| Random rand = new Random(); | |
| for (int t = 0; t < TESTS_COUNT; t++) { | |
| int operations = rand.nextInt(OPERATIONS_COUNT); | |
| int size = 1 + rand.nextInt(MAX_SIZE_INCLUSIVE); | |
| HashSet<HashtableElement> jset = new HashSet<>(); | |
| HashtableOpenAddressLinearProbingImpl<HashtableElement> set = new HashtableOpenAddressLinearProbingImpl<>( | |
| size, HashFunctionClosedAddressMethod.DIVISION); | |
| for (int i = 0; i < operations; i++) { | |
| int ch = rand.nextInt(5); | |
| HashtableElement element = new HashtableElement(rand.nextInt(MAX_ELEMENT_VALUE)); | |
| if (ch == 0) { | |
| try { | |
| set.insert(element); | |
| jset.add(element); | |
| } catch (HashtableOverflowException ex) { | |
| assertEquals(size, jset.size()); | |
| } | |
| } else if (ch == 1) { | |
| set.remove(element); | |
| jset.remove(element); | |
| } else if (ch == 2) { | |
| if (jset.contains(element)) { | |
| assertEquals(element, set.search(element)); | |
| } else { | |
| assertNull(set.search(element)); | |
| } | |
| } else if (ch == 3) { | |
| assertEquals(jset.isEmpty(), set.isEmpty()); | |
| } else if (ch == 4) { | |
| assertEquals(jset.size(), set.size()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you should try to think more about trick tests than trying to generate randomly tests that will break your code!!!