@Test public void next() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); assertThat(it.next(), is(new int[]{0, 1, 2, 7, 8, 9})); assertThat(it.next(), is(new int[]{0, 9, 8, 7, 2, 1})); assertThat(it.next(), is(new int[]{1, 0, 9, 8, 7, 2})); assertThat(it.next(), is(new int[]{1, 2, 7, 8, 9, 0})); assertThat(it.next(), is(new int[]{2, 1, 0, 9, 8, 7})); assertThat(it.next(), is(new int[]{2, 3, 4, 5, 6, 7})); assertThat(it.next(), is(new int[]{2, 7, 6, 5, 4, 3})); assertThat(it.next(), is(new int[]{2, 7, 8, 9, 0, 1})); assertThat(it.next(), is(new int[]{3, 2, 7, 6, 5, 4})); assertThat(it.next(), is(new int[]{3, 4, 5, 6, 7, 2})); assertThat(it.next(), is(new int[]{4, 3, 2, 7, 6, 5})); assertThat(it.next(), is(new int[]{4, 5, 6, 7, 2, 3})); assertThat(it.next(), is(new int[]{5, 4, 3, 2, 7, 6})); assertThat(it.next(), is(new int[]{5, 6, 7, 2, 3, 4})); assertThat(it.next(), is(new int[]{6, 5, 4, 3, 2, 7})); assertThat(it.next(), is(new int[]{6, 7, 2, 3, 4, 5})); assertThat(it.next(), is(new int[]{7, 2, 1, 0, 9, 8})); assertThat(it.next(), is(new int[]{7, 2, 3, 4, 5, 6})); assertThat(it.next(), is(new int[]{7, 6, 5, 4, 3, 2})); assertThat(it.next(), is(new int[]{7, 8, 9, 0, 1, 2})); assertThat(it.next(), is(new int[]{8, 7, 2, 1, 0, 9})); assertThat(it.next(), is(new int[]{8, 9, 0, 1, 2, 7})); assertThat(it.next(), is(new int[]{9, 0, 1, 2, 7, 8})); assertThat(it.next(), is(new int[]{9, 8, 7, 2, 1, 0})); }
@Test public void testNextM() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.nextM(0, -1), is(0)); assertThat(state.nextM(0, 0), is(1)); assertThat(state.nextM(0, 1), is(2)); state.m2[1] = 0; // 1 has been mapped and should be skipped over assertThat(state.nextM(0, 0), is(2)); }
@Test public void testNextN() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.nextN(0), is(0)); state.size = 1; assertThat(state.nextN(0), is(1)); state.size = 2; assertThat(state.nextN(0), is(2)); }
@Test public void hasNext2() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); int cnt = 0; Iterator<int[]> it = new StateStream(state); while (it.hasNext()) { assertNotNull(it.next()); cnt++; } assertThat(cnt, is(24)); }
@Test public void accessors() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); state.size = 1; assertThat(state.size(), is(1)); assertThat(state.nMax(), is(state.g1.length)); assertThat(state.mMax(), is(state.g2.length)); }
@Test public void mapping() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); state.m1[0] = 1; state.m1[1] = 2; assertThat(state.mapping(), is(state.m1)); assertThat(state.mapping(), is(not(sameInstance(state.m1)))); }
@Test public void infeasibleBonds() throws Exception { BondMatcher mock = mock(BondMatcher.class); when(mock.matches(any(IBond.class), any(IBond.class))).thenReturn(false); VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), mock); state.m1[0] = 0; state.m1[1] = 1; state.m1[2] = 2; state.m1[3] = 3; state.m1[4] = 4; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { assertFalse(state.feasible(i, j)); } } }
@Test public void infeasibleBonds() throws Exception { BondMatcher mock = mock(BondMatcher.class); when(mock.matches(any(IBond.class), any(IBond.class))).thenReturn(false); VFState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), mock); state.m1[0] = 0; state.m1[1] = 1; state.m1[2] = 2; state.m1[3] = 3; state.m1[4] = 4; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { assertFalse(state.feasible(i, j)); } } }
@Test(expected = UnsupportedOperationException.class) public void remove() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); it.remove(); }
@Test public void hasNext() throws Exception { VFSubState state = createNaphthaleneToBenzene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); assertFalse(it.hasNext()); }
@Test public void anyMatch() throws Exception { AtomMatcher matcher = AtomMatcher.forAny(); IAtom atom1 = mock(IAtom.class); IAtom atom2 = mock(IAtom.class); IAtom atom3 = mock(IAtom.class); when(atom1.getAtomicNumber()).thenReturn(6); when(atom2.getAtomicNumber()).thenReturn(7); when(atom3.getAtomicNumber()).thenReturn(8); assertTrue(matcher.matches(atom1, atom2)); assertTrue(matcher.matches(atom2, atom1)); assertTrue(matcher.matches(atom1, atom3)); assertTrue(matcher.matches(atom3, atom1)); assertTrue(matcher.matches(atom2, atom3)); assertTrue(matcher.matches(atom1, null)); assertTrue(matcher.matches(null, null)); }
@Test public void add() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.matrix.fix(), is(new int[][]{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
@Test public void infeasibleTerminalCount() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(0, 0)); // 0,0 is feasible // XXX: depends on molecule order not changing state.t1[1] = 1; state.t1[5] = 1; assertFalse(state.feasible(0, 0)); // 0,0 is infeasible }
@Test public void infeasibleRemainCount() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(0, 0)); // 0,0 is feasible // XXX: depends on molecule order not changing state.m1[1] = 1; state.m1[5] = 5; state.t2[1] = 1; state.t2[9] = 1; assertFalse(state.feasible(0, 0)); // 0,0 is infeasible }
@Test public void remove() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.matrix.fix(), is(new int[][]{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
@Test public void infeasibleTerminalCount() throws Exception { VFState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(4, 4)); // 4, 4 is feasible state.add(0, 0); state.add(1, 1); state.add(2, 2); state.add(3, 3); assertFalse(state.feasible(4, 4)); // 4, 4 is infeasible }