package net.sf.javaml.core; import static org.junit.Assert.*; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedSet; import org.junit.Test; public class TestAbstractInstance { public static class MyInstance extends AbstractInstance{ SparseInstance si = new SparseInstance(new double[]{1, 2, 3}); public MyInstance(){} public MyInstance(Object classValue){ super(classValue); } public int noAttributes() { return si.noAttributes(); } public int size() { return si.size(); } public double value(int pos) { return si.value(pos); } public SortedSet keySet() { return si.keySet(); } public void removeAttribute(int i) { si.removeAttribute(i); } public Instance copy() { return si.copy(); } public void removeAttributes(Set indices) { si.removeAttributes(indices); } public boolean isEmpty() { return si.isEmpty(); } public boolean containsKey(Object key) { return si.containsKey(key); } public boolean containsValue(Object value) { return si.containsValue(value); } public Double get(Object key) { return si.get(key); } public Double put(Integer key, Double value) { return si.put(key, value); } public Double remove(Object key) { return si.remove(key); } public void putAll(Map m) { si.putAll(m); } public void clear() { si.clear(); } public Collection values() { return si.values(); } public Set> entrySet() { return si.entrySet(); } } @Test public void test(){ MyInstance mi = new MyInstance(); mi = new MyInstance(new Integer(5)); assertEquals(new Integer(5), mi.classValue()); mi.setClassValue(new Integer(6)); assertEquals(new Integer(6), mi.classValue()); Iterator it = mi.iterator(); int cnt = 0; while(it.hasNext()){ it.next(); cnt++; } assertEquals(3, cnt); mi = new MyInstance(); assertEquals(new MyInstance().minus(0), mi.minus(0)); assertEquals(new MyInstance().minus(0), mi.minus(new SparseInstance(new double[]{0.0, 0.0, 0.0}))); assertNotNull(mi.add(1)); assertNotNull(mi.add(new SparseInstance(new double[]{1.0, 1.0, 1.0}))); assertNotNull(mi.divide(1)); assertNotNull(mi.divide(new SparseInstance(new double[]{1.0, 1.0, 1.0}))); assertNotNull(mi.multiply(1)); assertNotNull(mi.multiply(new SparseInstance(new double[]{1.0, 1.0, 1.0}))); mi.sqrt(); assertFalse(new MyInstance().hashCode() == new MyInstance().hashCode()); assertFalse(new MyInstance().equals(new MyInstance())); assertFalse(new MyInstance().equals(null)); assertFalse(new MyInstance().equals(new Object())); } }