emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[QZ3] fail to pass the robustness test #76

Closed Lokakaaa closed 3 years ago

Lokakaaa commented 3 years ago

Replace # in the title with the appropriate quiz number. I have tested my code using different datasets and they all went well, and I can also print out the array generated by the robustness test in a sorted order(using print array added by myself). However, I cannot pass the robustness test. Can you please help me find if anything is wrong? image

Here is the link to my code https://github.com/Lokakaaa/dsa-java/blob/master/src/main/java/edu/emory/cs/sort/distribution/RadixSortQuiz.java Thank you so much.

lujiaying commented 3 years ago

https://github.com/Lokakaaa/dsa-java/blob/master/src/main/java/edu/emory/cs/sort/distribution/RadixSortQuiz.java#L9

cum is not reset to zero after sort one input array. That means in the next invoked sort(), cum is not 0 and may lead to unexpected errors.

lujiaying commented 3 years ago
    void testRobustness(AbstractSort<Integer> engine) {
        final int iter = 100;
        final int size = 1000;
        final Random rand = new Random();
        Integer[] original, sorted;

        for (int i = 0; i < iter; i++) {
            original = Stream.generate(() -> rand.nextInt(size)).limit(size).toArray(Integer[]::new);
            sorted = Arrays.copyOf(original, size);

            engine.sort(original);
            Arrays.sort(sorted);
            assertArrayEquals(original, sorted);
        }
    }

engine would be tested with multiple arrays. I highly doubt errors are introduced due to that cum not be reset.

Also, I am not trying to say eliminate cum issue would lead your codes perfect. But this is at least one error I noticed at first trial.

lujiaying commented 3 years ago

I have tested my code using different datasets and they all went well,

I tested your codes, it succeeded for one input array. However, not able to deal with multiple arrays need to be tested.

Lokakaaa commented 3 years ago

You are right, my problem is solved. Thank you so much!

I have tested my code using different datasets and they all went well,

I tested your codes, it succeeded for one input array. However, not able to deal with multiple arrays need to be tested.