summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java
blob: 3f4d58ba26759c732a34608f46aa2573f4ed333b (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package au.id.zancanaro.javacheck;

import au.id.zancanaro.javacheck.annotations.Property;
import au.id.zancanaro.javacheck.junit.Properties;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.reverse;
import static java.util.Collections.sort;
import static org.junit.Assert.assertEquals;

@RunWith(Properties.class)
public class SimpleListOperationsTest {

    private final static int runs = 1000;
    private final static int maxSize = 1000;

    @Property(maxSize = maxSize, runs = runs)
    public void sortingIsIdempotent(List<Integer> list) {
        List<Integer> left = new ArrayList<>(list);
        sort(left);

        List<Integer> right = new ArrayList<>(list);
        sort(right);
        sort(right);

        assertEquals(left, right);
    }

    @Property(maxSize = 100, runs = runs)
    public void reverseIsItsOwnInverse(List<String> list) {
        List<String> reversed = new ArrayList<>(list);
        reverse(reversed);
        reverse(reversed);

        assertEquals(list, reversed);
    }
}