summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java
blob: 93a40e20a6e3dc63a8df1d469ceb2956b3f79156 (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
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 {

    @Property
    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
    public void reverseIsInvolution(List<String> list) {
        List<String> newList = new ArrayList<>(list);
        reverse(newList);
        reverse(newList);

        assertEquals(list, newList);
    }
}