public class Test {

    static value class IntValue {
        int value;

        static final int[] EDGE_CASES = {
                0, -1, 1,
                Integer.MIN_VALUE, Integer.MAX_VALUE
        };

        public IntValue(int index) {
            value = EDGE_CASES[index];
        }

        public String toString() {
            return "IntValue(" + value +
                   ", bits=0x" + Integer.toHexString(value) + ")";
        }

        static boolean cmp(int i, int j) {
            return EDGE_CASES[i] == EDGE_CASES[j];
        }
    }

    static value class NestedValue {
        IntValue value;

        static final IntValue[] EDGE_CASES = {
                null, new IntValue(0), new IntValue(1), new IntValue(2),
                new IntValue(3), new IntValue(0)
        };

        public NestedValue(int index) {
            value = EDGE_CASES[index];
        }

        public String toString() {
            return "NestedValue(" + value + ")";
        }

        static boolean cmp(int i, int j) {
            return EDGE_CASES[i] == EDGE_CASES[j];
        }
    }

    public static boolean testNestedValue(NestedValue v1, NestedValue v2) {
        return v1 == v2;
    }

    public static void main(String[] args) {
        for (int k = 0; k < 10_000; ++k) {
            // NestedValue
            for (int i = 0; i < NestedValue.EDGE_CASES.length; ++i) {
                for (int j = 0; j < NestedValue.EDGE_CASES.length; ++j) {
                    NestedValue val1 = new NestedValue(i);
                    NestedValue val2 = new NestedValue(j);
                    boolean res = testNestedValue(val1, val2);
                    if (res != (NestedValue.cmp(i, j))) {
                        throw new RuntimeException("Incorrect result '" + res + "' for " + val1 + " == " + val2);
                    }
                }
            }
        }
    }
}
