/* * File: VectorEntryIndexComparatorTest.java * Authors: Justin Basilico * Company: Sandia National Laboratories * Project: Cognitive Framework Lite * * Copyright July 31, 2006, Sandia Corporation. Under the terms of Contract * DE-AC04-94AL85000, there is a non-exclusive license for use of this work by * or on behalf of the U.S. Government. Export of this program may require a * license from the United States Government. See CopyrightHistory.txt for * complete details. * * */ package gov.sandia.cognition.math.matrix; import java.util.Iterator; import java.util.Random; import junit.framework.*; /** * This class implements JUnit tests for the following classes: * * VectorEntryIndexComparator * * @author Justin Basilico * @since 1.0 */ public class VectorEntryIndexComparatorTest extends TestCase { protected Random random = new Random(); public VectorEntryIndexComparatorTest( String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(VectorEntryIndexComparatorTest.class); return suite; } /** * Test of lowestIndex method, of class gov.sandia.isrc.math.matrix.VectorEntryIndexComparator. */ public void testLowestIndex() { Vector first = VectorFactory.getDefault().createUniformRandom(10, -1.0, 1.0, random); Vector second = VectorFactory.getDefault().createUniformRandom(10, -1.0, 1.0, random); VectorEntryIndexComparator instance = VectorEntryIndexComparator.INSTANCE; Iterator<VectorEntry> it1 = first.iterator(); it1.next(); Iterator<VectorEntry> it2 = first.iterator(); it2.next(); it2.next(); it2.next(); VectorEntry entry1 = it1.next(); VectorEntry entry2 = it2.next(); assertEquals(EntryIndexComparator.Compare.BOTH_ENTRIES_NULL, instance.lowestIndex(null, null)); assertEquals(EntryIndexComparator.Compare.ENTRIES_EQUAL, instance.lowestIndex(entry1, entry1)); assertEquals(EntryIndexComparator.Compare.ENTRIES_EQUAL, instance.lowestIndex(entry2, entry2)); assertEquals(EntryIndexComparator.Compare.FIRST_ENTRY_NULL, instance.lowestIndex(null, entry2)); assertEquals(EntryIndexComparator.Compare.FIRST_LOWEST, instance.lowestIndex(entry1, entry2)); assertEquals(EntryIndexComparator.Compare.SECOND_ENTRY_NULL, instance.lowestIndex(entry1, null)); assertEquals(EntryIndexComparator.Compare.SECOND_LOWEST, instance.lowestIndex(entry2, entry1)); } }