19 package examples.quickcheck;
21 import java.util.Collections;
22 import java.util.List;
60 public static void main(String[] args)
62 FaultySort<Integer> fs =
new FaultySort<Integer>();
65 protected boolean evaluate(List<Integer> x) {
71 System.out.println(
"Assertion is false");
72 System.out.println(a.
getInitial() +
" produces " + fs.sort(a.
getInitial()) +
" and is not sorted");
73 System.out.println(a.
getIterations().size() +
" shrinking steps");
74 System.out.println(a.
getShrunk() +
" produces " + fs.sort(a.
getShrunk()) +
" and is also not sorted");
83 protected static class FaultySort<T>
85 @SuppressWarnings(
"unchecked")
86 public List<T> sort(List<T> list)
90 ini_list.addAll(list);
91 for (
int i = 0; i < list.size(); i++)
93 int index_to_remove = -1;
95 for (
int j = 0; j < ini_list.size(); j++)
97 T e = ini_list.get(j);
98 if (to_insert ==
null)
105 if (to_insert instanceof Comparable)
107 int value = ((Comparable<T>) to_insert).
compareTo(e);
116 new_list.add(to_insert);
117 ini_list.remove(index_to_remove);
120 if (list.size() > 4 && ((int) list.get(3)) + ((
int) list.get(4)) > 1000)
122 Collections.swap(new_list, 3, 4);
128 @SuppressWarnings(
"unchecked")
131 for (
int i = 0; i < list.size() - 1; i++)
133 Object o1 = list.get(i);
134 Object o2 = list.get(i + 1);
135 if (o1 instanceof Comparable)
137 if (((Comparable<Object>) o1).compareTo(o2) > 0)