1 2 public class DoubleCmpTests { 3 4 private static boolean test_isEq(double a, double b) { 5 return a == b; 6 } 7 8 private static boolean test_isNe(double a, double b) { 9 return a != b; 10 } 11 12 private static boolean test_isLt(double a, double b) { 13 return a < b; 14 } 15 16 private static boolean test_isLe(double a, double b) { 17 return a <= b; 18 } 19 20 private static boolean test_isGe(double a, double b) { 21 return a >= b; 22 } 23 24 private static boolean test_isGt(double a, double b) { 25 return a > b; 26 } 27 28 private static boolean test_isEqC(double a) { 29 return a == 7.; 30 } 31 32 private static boolean test_isNeC(double a) { 33 return a != 7.; 34 } 35 36 private static boolean test_isLtC(double a) { 37 return a < 7.; 38 } 39 40 private static boolean test_isLeC(double a) { 41 return a <= 7.; 42 } 43 44 private static boolean test_isGeC(double a) { 45 return a >= 7.; 46 } 47 48 private static boolean test_isGtC(double a) { 49 return a > 7.; 50 } 51 52 private static void assertThat(boolean assertion) { 53 if (! assertion) { 54 throw new AssertionError(); 55 } 56 } 57 58 public static void main(String[] args) { 59 assertThat(test_isEq(7., 7.)); 60 assertThat(! test_isEq(70., 7.)); 61 assertThat(! test_isNe(7., 7.)); 62 assertThat(test_isNe(70., 7.)); 63 64 assertThat(test_isLt(7., 70.)); 65 assertThat(! test_isLt(70., 7.)); 66 assertThat(! test_isLt(7., 7.)); 67 68 assertThat(test_isLe(7., 70.)); 69 assertThat(! test_isLe(70., 7.)); 70 assertThat(test_isLe(7., 7.)); 71 72 assertThat(!test_isGe(7., 70.)); 73 assertThat(test_isGe(70., 7.)); 74 assertThat(test_isGe(7., 7.)); 75 76 assertThat(!test_isGt(7., 70.)); 77 assertThat(test_isGt(70., 7.)); 78 assertThat(! test_isGt(7., 7.)); 79 80 81 assertThat(test_isEqC(7.)); 82 assertThat(! test_isEqC(70.)); 83 assertThat(! test_isNeC(7.)); 84 assertThat(test_isNeC(70.)); 85 86 assertThat(test_isLtC(6.)); 87 assertThat(! test_isLtC(70.)); 88 assertThat(! test_isLtC(7.)); 89 90 assertThat(test_isLeC(6.)); 91 assertThat(! test_isLeC(70.)); 92 assertThat(test_isLeC(7.)); 93 94 assertThat(!test_isGeC(6.)); 95 assertThat(test_isGeC(70.)); 96 assertThat(test_isGeC(7.)); 97 98 assertThat(!test_isGtC(6.)); 99 assertThat(test_isGtC(70.)); 100 assertThat(! test_isGtC(7.)); 101 } 102 }