MDLValence { static int implicitValence(int elem, int q, int val) { switch (elem) { case 1: case 3: case 11: case 19: case 37: case 55: case 87: if (q == 0 && val <= 1) return 1; break; case 4: case 12: case 20: case 38: case 56: case 88: switch (q) { case 0: if (val <= 2) return 2; break; case 1: if (val <= 1) return 1; break; } break; case 5: switch (q) { case -4: if (val <= 1) return 1; break; case -3: if (val <= 2) return 2; break; case -2: if (val <= 3) return 3; if (val <= 5) return 5; break; case -1: if (val <= 4) return 4; break; case 0: if (val <= 3) return 3; break; case 1: if (val <= 2) return 2; break; case 2: if (val <= 1) return 1; break; } break; case 6: switch (q) { case -3: if (val <= 1) return 1; break; case -2: if (val <= 2) return 2; break; case -1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 0: if (val <= 4) return 4; break; case 1: if (val <= 3) return 3; break; case 2: if (val <= 2) return 2; break; case 3: if (val <= 1) return 1; break; } break; case 7: switch (q) { case -2: if (val <= 1) return 1; break; case -1: if (val <= 2) return 2; break; case 0: if (val <= 3) return 3; if (val <= 5) return 5; break; case 1: if (val <= 4) return 4; break; case 2: if (val <= 3) return 3; break; case 3: if (val <= 2) return 2; break; case 4: if (val <= 1) return 1; break; } break; case 8: switch (q) { case -1: if (val <= 1) return 1; break; case 0: if (val <= 2) return 2; break; case 1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 2: if (val <= 4) return 4; break; case 3: if (val <= 3) return 3; break; case 4: if (val <= 2) return 2; break; case 5: if (val <= 1) return 1; break; } break; case 9: switch (q) { case 0: if (val <= 1) return 1; break; case 1: if (val <= 2) return 2; break; case 2: if (val <= 3) return 3; if (val <= 5) return 5; break; case 3: if (val <= 4) return 4; break; case 4: if (val <= 3) return 3; break; case 5: if (val <= 2) return 2; break; case 6: if (val <= 1) return 1; break; } break; case 13: switch (q) { case -4: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -3: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -2: if (val <= 3) return 3; if (val <= 5) return 5; break; case -1: if (val <= 4) return 4; break; case 0: if (val <= 3) return 3; break; case 1: if (val <= 2) return 2; break; case 2: if (val <= 1) return 1; break; } break; case 14: switch (q) { case -3: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -2: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 0: if (val <= 4) return 4; break; case 1: if (val <= 3) return 3; break; case 2: if (val <= 2) return 2; break; case 3: if (val <= 1) return 1; break; } break; case 15: switch (q) { case -2: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 0: if (val <= 3) return 3; if (val <= 5) return 5; break; case 1: if (val <= 4) return 4; break; case 2: if (val <= 3) return 3; break; case 3: if (val <= 2) return 2; break; case 4: if (val <= 1) return 1; break; } break; case 16: switch (q) { case -1: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 0: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 2: if (val <= 4) return 4; break; case 3: if (val <= 3) return 3; break; case 4: if (val <= 2) return 2; break; case 5: if (val <= 1) return 1; break; } break; case 17: switch (q) { case 0: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 2: if (val <= 3) return 3; if (val <= 5) return 5; break; case 3: if (val <= 4) return 4; break; case 4: if (val <= 3) return 3; break; case 5: if (val <= 2) return 2; break; case 6: if (val <= 1) return 1; break; } break; case 31: switch (q) { case -4: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -3: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -2: if (val <= 3) return 3; if (val <= 5) return 5; break; case -1: if (val <= 4) return 4; break; case 0: if (val <= 3) return 3; break; case 2: if (val <= 1) return 1; break; } break; case 32: switch (q) { case -3: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -2: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 0: if (val <= 4) return 4; break; case 1: if (val <= 3) return 3; break; case 3: if (val <= 1) return 1; break; } break; case 33: switch (q) { case -2: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 0: if (val <= 3) return 3; if (val <= 5) return 5; break; case 1: if (val <= 4) return 4; break; case 2: if (val <= 3) return 3; break; case 4: if (val <= 1) return 1; break; } break; case 34: switch (q) { case -1: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 0: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 2: if (val <= 4) return 4; break; case 3: if (val <= 3) return 3; break; case 5: if (val <= 1) return 1; break; } break; case 35: switch (q) { case 0: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 2: if (val <= 3) return 3; if (val <= 5) return 5; break; case 3: if (val <= 4) return 4; break; case 4: if (val <= 3) return 3; break; case 6: if (val <= 1) return 1; break; } break; case 49: switch (q) { case -4: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -3: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -2: if (val <= 3) return 3; if (val <= 5) return 5; break; case -1: if (val <= 2) return 2; if (val <= 4) return 4; break; case 0: if (val <= 3) return 3; break; case 2: if (val <= 1) return 1; break; } break; case 50: case 82: switch (q) { case -3: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -2: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 0: if (val <= 2) return 2; if (val <= 4) return 4; break; case 1: if (val <= 3) return 3; break; case 3: if (val <= 1) return 1; break; } break; case 51: case 83: switch (q) { case -2: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 0: if (val <= 3) return 3; if (val <= 5) return 5; break; case 1: if (val <= 2) return 2; if (val <= 4) return 4; break; case 2: if (val <= 3) return 3; break; case 4: if (val <= 1) return 1; break; } break; case 52: case 84: switch (q) { case -1: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 0: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 1: if (val <= 3) return 3; if (val <= 5) return 5; break; case 2: if (val <= 2) return 2; if (val <= 4) return 4; break; case 3: if (val <= 3) return 3; break; case 5: if (val <= 1) return 1; break; } break; case 53: case 85: switch (q) { case 0: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case 1: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case 2: if (val <= 3) return 3; if (val <= 5) return 5; break; case 3: if (val <= 2) return 2; if (val <= 4) return 4; break; case 4: if (val <= 3) return 3; break; case 6: if (val <= 1) return 1; break; } break; case 81: switch (q) { case -4: if (val <= 1) return 1; if (val <= 3) return 3; if (val <= 5) return 5; if (val <= 7) return 7; break; case -3: if (val <= 2) return 2; if (val <= 4) return 4; if (val <= 6) return 6; break; case -2: if (val <= 3) return 3; if (val <= 5) return 5; break; case -1: if (val <= 2) return 2; if (val <= 4) return 4; break; case 0: if (val <= 1) return 1; if (val <= 3) return 3; break; } break; } return val; } private  MDLValence();   }
@Test public void nitrogen_neutral() { assertThat(MDLValence.implicitValence(7, 0, 0), is(3)); assertThat(MDLValence.implicitValence(7, 0, 1), is(3)); assertThat(MDLValence.implicitValence(7, 0, 2), is(3)); assertThat(MDLValence.implicitValence(7, 0, 3), is(3)); assertThat(MDLValence.implicitValence(7, 0, 4), is(5)); assertThat(MDLValence.implicitValence(7, 0, 5), is(5)); assertThat(MDLValence.implicitValence(7, 0, 6), is(6)); }
@Test public void nitrogen_cation() { assertThat(MDLValence.implicitValence(7, +1, 0), is(4)); assertThat(MDLValence.implicitValence(7, +1, 1), is(4)); assertThat(MDLValence.implicitValence(7, +1, 2), is(4)); assertThat(MDLValence.implicitValence(7, +1, 3), is(4)); assertThat(MDLValence.implicitValence(7, +1, 4), is(4)); assertThat(MDLValence.implicitValence(7, +1, 5), is(5)); assertThat(MDLValence.implicitValence(7, +1, 6), is(6)); }
@Test public void nitrogen_anion() { assertThat(MDLValence.implicitValence(7, -1, 0), is(2)); assertThat(MDLValence.implicitValence(7, -1, 1), is(2)); assertThat(MDLValence.implicitValence(7, -1, 2), is(2)); assertThat(MDLValence.implicitValence(7, -1, 3), is(3)); assertThat(MDLValence.implicitValence(7, -1, 4), is(4)); assertThat(MDLValence.implicitValence(7, -1, 5), is(5)); assertThat(MDLValence.implicitValence(7, -1, 6), is(6)); }