/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j;

import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import prm4j.api.Parameter;
import prm4j.api.Symbol;
import prm4j.util.FSMDefinitions;

/**
 * Provides utilities for testing.
 */
public abstract class AbstractTest extends FSMDefinitions /* we mix in other definitions layer by layer */{

    public final static Set<Parameter<?>> EMPTY_PARAMETER_SET = new HashSet<Parameter<?>>();

    /**
     * Downcast SymbolN to Symbol.
     *
     * @param values
     * @return
     */
    public static Set<Symbol> asSet(Symbol... values) {
	Set<Symbol> set = new HashSet<Symbol>();
	for (Symbol s : values) {
	    set.add(s);
	}
	return set;
    }

    public static Set<Parameter<?>> asSet(Parameter<?>... values) {
	Set<Parameter<?>> set = new HashSet<Parameter<?>>();
	for (Parameter<?> s : values) {
	    set.add(s);
	}
	return set;
    }

    public static <T> List<T> list(T... objects) {
	List<T> result = new ArrayList<T>();
	for (T t : objects)
		result.add(t);
	return result;
}

    /**
     * assertArrayEquals(boolean[] a1, boolean[] a2) not implemented in jUnit for some reason, see
     * https://github.com/KentBeck/junit/issues/86
     *
     * @param expected
     * @param actual
     */
    public static void assertBooleanArrayEquals(boolean[] expected, boolean[] actual) {
	if (expected.length != actual.length)
	    fail("Expected:<" + Arrays.toString(expected) + "> but was: <" + Arrays.toString(actual) + ">");
	for (int i = 0; i < expected.length; i++) {
	    if (expected[i] != actual[i])
		fail();
	}
    }

}

@@ -1449,17 +1449,20 @@
 jects)%0A%09
-%09
+    
 result.a
@@ -1484,18 +1484,22 @@
 result;%0A
+    
 %7D%0A
-
 %0A    /**
@@ -2017,16 +2017,16 @@
 ual%5Bi%5D)%0A
-
 %09%09fail()
@@ -2037,10 +2037,757 @@
 %0A    %7D%0A%0A
+    public static void assert2DimArrayEquals(Object%5B%5D%5B%5D expected, Object%5B%5D%5B%5D actual) %7B%0A%09if (expected.length != actual.length)%0A%09    fail(%22Expected:%3C%22 + Arrays.toString(expected) + %22%3E but was: %3C%22 + Arrays.toString(actual) + %22%3E%22);%0A%09for (int i = 0; i %3C expected.length; i++) %7B%0A%09    if (expected%5Bi%5D.length != actual%5Bi%5D.length)%0A%09%09fail(%222-dim array differs in row %22 + i + %22. Expected:%3C%22 + Arrays.toString(expected%5Bi%5D) + %22%3E but was: %3C%22%0A%09%09%09+ Arrays.toString(actual%5Bi%5D) + %22%3E%22);%0A%09    for (int j = 0; j %3C expected%5Bi%5D.length; j++) %7B%0A%09%09if (!expected%5Bi%5D%5Bj%5D.equals(actual%5Bi%5D%5Bj%5D)) %7B%0A%09%09    fail(%222-dim array differs in at %5B%22 + i + %22%5D%5B%22 + j + %22%5D. Expected:%3C%22 + expected%5Bi%5D%5Bj%5D.toString()%0A%09%09%09    + %22%3E but was: %3C%22 + actual%5Bi%5D%5Bj%5D.toString() + %22%3E%22);%0A%09%09%7D%0A%09    %7D%0A%09%7D%0A    %7D%0A%0A
 %7D%0A

Add test method to compare 2-dim arrays