summaryrefslogtreecommitdiffstats
path: root/tests/pureJava/SwitchBounds.java
blob: cb52d8554e4f509e60e786c2fb6c64e74680a6e2 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import org.aspectj.testing.Tester;

public class SwitchBounds {

    static int minZero(int key) {
	switch (key) {
	case Integer.MIN_VALUE:
	    return Integer.MIN_VALUE;
	case 0:
	    return 0;
	default:
	    return key;
	}
    }

    static int maxZero(int key) {
	switch (key) {
	case Integer.MAX_VALUE:
	    return Integer.MAX_VALUE;
	case 0:
	    return 0;
	default:
	    return key;
	}
    }

    static int minMax(int key) {
	switch (key) {
	case Integer.MIN_VALUE:
	    return Integer.MIN_VALUE;
	case Integer.MAX_VALUE:
	    return Integer.MAX_VALUE;
	default:
	    return key;
	}
    }

    static int fiveMins(int key) {
	switch (key) {
	case Integer.MIN_VALUE:
	    return Integer.MIN_VALUE;
	case (Integer.MIN_VALUE + 1):
	    return (Integer.MIN_VALUE + 1);
	case (Integer.MIN_VALUE + 2):
	    return (Integer.MIN_VALUE + 2);
	case (Integer.MIN_VALUE + 3):
	    return (Integer.MIN_VALUE + 3);
	case (Integer.MIN_VALUE + 4):
	    return (Integer.MIN_VALUE + 4);
	case (Integer.MIN_VALUE + 5):
	    return (Integer.MIN_VALUE + 5);
	default:
	    return key;
	}
    }

    public static void main(String[] args) {
	int MIN = Integer.MIN_VALUE;
	int MAX = Integer.MAX_VALUE;

	Tester.checkEqual(MIN, minZero(MIN));
	Tester.checkEqual(0, minZero(0));
	Tester.checkEqual(37, minZero(37));

	Tester.checkEqual(MAX, maxZero(MAX));
	Tester.checkEqual(0, maxZero(0));
	Tester.checkEqual(37, maxZero(37));

	Tester.checkEqual(MIN, minMax(MIN));
	Tester.checkEqual(MAX, minMax(MAX));
	Tester.checkEqual(37, minMax(37));

	Tester.checkEqual(MIN, fiveMins(MIN));
	Tester.checkEqual(MIN + 1, fiveMins(MIN + 1));
	Tester.checkEqual(MIN + 2, fiveMins(MIN + 2));
	Tester.checkEqual(MIN + 3, fiveMins(MIN + 3));
	Tester.checkEqual(MIN + 4, fiveMins(MIN + 4));
	Tester.checkEqual(MIN + 5, fiveMins(MIN + 5));
	Tester.checkEqual(MIN + 37, fiveMins(MIN + 37));
    }
}