Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test cases #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@
<groupId>net.imagej</groupId>
<artifactId>imagej-common</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version> <!-- Use the latest version -->
<scope>test</scope> <!-- Make sure Mockito is only included for testing -->
</dependency>
<!-- ImgLib2 dependencies -->
<dependency>
<groupId>net.imglib2</groupId>
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/fiji/plugin/trackmate/SpotCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +424,26 @@ public void testPut()
}
}

@Test
public void testFirstKey()
{
// First key should be frame 1
assertEquals( frames.get( 0 ), sc.firstKey() );

// Create a new frame content
final int N_SPOTS_TO_ADD = 20;
final HashSet< Spot > spots = new HashSet<>( N_SPOTS_TO_ADD );
for ( int i = 0; i < N_SPOTS_TO_ADD; i++ )
@Test
public void testFirstKey()
{
spots.add( new Spot( -1d, -1d, -1d, 1d, -1d ) );
}
// Add it to a new frame
final int targetFrame = -1;
sc.put( targetFrame, spots );
// First key should be frame 1
assertEquals( frames.get( 0 ), sc.firstKey() );

// First key should be new frame
assertEquals( targetFrame, sc.firstKey().longValue() );
}
// Create a new frame content
final int N_SPOTS_TO_ADD = 20;
final HashSet< Spot > spots = new HashSet<>( N_SPOTS_TO_ADD );
for ( int i = 0; i < N_SPOTS_TO_ADD; i++ )
{
spots.add( new Spot( -1d, -1d, -1d, 1d, -1d ) );
}
// Add it to a new frame
final int targetFrame = -1;
sc.put( targetFrame, spots );

// First key should be new frame
assertEquals( targetFrame, sc.firstKey().longValue() );
}

@Test
public void testLastKey()
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/fiji/plugin/trackmate/features/FeatureUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fiji.plugin.trackmate.features;

import static org.junit.Assert.assertNotNull;
import org.junit.Test;

import fiji.plugin.trackmate.Model;

import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings.TrackMateObject;

public class FeatureUtilsTest {


@Test
public void testCollectFeatureValuesForEdges() {
Model model = FeatureUtils.DUMMY_MODEL;
double[] values = FeatureUtils.collectFeatureValues("SomeFeature", TrackMateObject.EDGES, model, true);
assertNotNull(values);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fiji.plugin.trackmate.graph;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Test;


public class FromContinousBranchesTest {

// Returns true if branches and links are not null and links are made of two spots.
@Test
public void test_behaviour_true() {
FromContinuousBranches obj = new FromContinuousBranches(new ArrayList<>(), new ArrayList<>());
boolean result = obj.checkInput();
assertTrue(result);
}

// Returns false if branches is null.
@Test
public void test_behaviour_false() {
FromContinuousBranches obj = new FromContinuousBranches(null, new ArrayList<>());
boolean result = obj.checkInput();
assertFalse(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int compare( final Spot o1, final Spot o2 )
public final void testBehavior()
{

// Sort names
// Sort names+
final String[] expectedSortedNames = names.clone();
final Comparator< String > alphabeticalOrder = new Comparator< String >()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ public void testTranspose()
}
}

@Test
public void test_valid_assignment_cost() {
// Create a SparseCostMatrix object with sample data
double[] cc = {1.0, 2.0, 3.0, 4.0};
int[] kk = {0, 1, 2, 3};
int[] number = {2, 2};
int nCols = 4;
SparseCostMatrix matrix = new SparseCostMatrix(cc, kk, number, nCols);

// Creating a valid assignment
int[] rowAssignment = {1, 3};

// Calculating the total assignment cost
double totalCost = matrix.totalAssignmentCost(rowAssignment);

// Assert that if total cost is correct
assertEquals(6.0, totalCost, 0.0001);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fiji.plugin.trackmate.tracking.kalman;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import fiji.plugin.trackmate.SpotCollection;
import fiji.plugin.trackmate.tracking.SpotTracker;

public class AdvancedKalmanTrackerFactoryTest {

@Test
public void testCreate() {
// Creating necessary mock objects
Map<String, Object> settings = new HashMap<>();
SpotCollection spots = mock(SpotCollection.class);

// Creating AdvancedKalmanTrackerFactory instance
AdvancedKalmanTrackerFactory factory = new AdvancedKalmanTrackerFactory();

// Testing create method
SpotTracker tracker = factory.create(spots, settings);
assertNotNull(tracker);
assertTrue(tracker instanceof AdvancedKalmanTracker);
}



// Returns False if the input settings map is empty.
@Test
public void test_empty_map() {
Map<String, Object> settings = new HashMap<>();
boolean result = new AdvancedKalmanTrackerFactory().checkSettingsValidity(settings);
assertFalse(result);
}

}