AbstractVFState extends State { @Override final boolean add(int n, int m) { if (!feasible(n, m)) return false; m1[n] = m; m2[m] = n; size = size + 1; for (int w : g1[n]) if (t1[w] == 0) t1[w] = size; for (int w : g2[m]) if (t2[w] == 0) t2[w] = size; return true; } AbstractVFState(final int[][] g1, final int[][] g2);   }
@Test public void addNonFeasible() { AbstractVFState state = new AbstractVFState(new int[4][], new int[6][]) { @Override boolean feasible(int n, int m) { return false; } }; assertFalse(state.add(0, 1)); assertThat(state.size, is(0)); assertThat(state.m1, is(new int[]{UNMAPPED, UNMAPPED, UNMAPPED, UNMAPPED})); assertThat(state.m2, is(new int[]{UNMAPPED, UNMAPPED, UNMAPPED, UNMAPPED, UNMAPPED, UNMAPPED})); assertThat(state.t1, is(new int[]{0, 0, 0, 0})); assertThat(state.t2, is(new int[]{0, 0, 0, 0, 0, 0})); }
@Test public void add() { int[][] g1 = new int[][]{{1}, {0, 2}, {1, 3}, {2}}; int[][] g2 = new int[][]{{1}, {0, 2}, {1, 3}, {2, 4}, {3, 5}, {4}}; AbstractVFState state = create(g1, g2); assertTrue(state.add(0, 1)); assertThat(state.size, is(1)); assertThat(state.m1, is(new int[]{1, UNMAPPED, UNMAPPED, UNMAPPED})); assertThat(state.m2, is(new int[]{UNMAPPED, 0, UNMAPPED, UNMAPPED, UNMAPPED, UNMAPPED})); assertThat(state.t1, is(new int[]{0, 1, 0, 0})); assertThat(state.t2, is(new int[]{1, 0, 1, 0, 0, 0})); assertTrue(state.add(1, 2)); assertThat(state.size, is(2)); assertThat(state.m1, is(new int[]{1, 2, UNMAPPED, UNMAPPED})); assertThat(state.m2, is(new int[]{UNMAPPED, 0, 1, UNMAPPED, UNMAPPED, UNMAPPED})); assertThat(state.t1, is(new int[]{2, 1, 2, 0})); assertThat(state.t2, is(new int[]{1, 2, 1, 2, 0, 0})); }