Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A few unit tests uncovering some issues with == comparisons
Change-Id: Ib013c284e1f742a6d7655ec2c81ae01ca2757b07
  • Loading branch information
egonw committed Nov 15, 2012
1 parent 75b5fe6 commit 46d48f9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 10 deletions.
44 changes: 41 additions & 3 deletions src/test/org/openscience/cdk/IsotopeTest.java
@@ -1,6 +1,5 @@
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
/* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
* 2012 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
Expand Down Expand Up @@ -80,4 +79,43 @@ public IChemObject newTestObject() {
Assert.assertEquals(80.0, i.getNaturalAbundance(), 0.001);
}

@Test public void testCompare_MassNumber() {
Isotope iso = new Isotope("C");
iso.setMassNumber(12);
Isotope iso2 = new Isotope("C");
iso2.setMassNumber((int)12.0);
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_MassNumberIntegers() {
Isotope iso = new Isotope("C");
iso.setMassNumber(new Integer(12));
Isotope iso2 = new Isotope("C");
iso2.setMassNumber(new Integer(12));
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_MassNumberIntegers_ValueOf() {
Isotope iso = new Isotope("C");
iso.setMassNumber(Integer.valueOf(12));
Isotope iso2 = new Isotope("C");
iso2.setMassNumber(Integer.valueOf(12));
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_ExactMass() {
Isotope iso = new Isotope("C");
iso.setExactMass(12.000000);
Isotope iso2 = new Isotope("C");
iso2.setExactMass(12.0);
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_NaturalAbundance() {
Isotope iso = new Isotope("C");
iso.setNaturalAbundance(12.000000);
Isotope iso2 = new Isotope("C");
iso2.setNaturalAbundance(12.0);
Assert.assertTrue(iso.compare(iso2));
}
}
50 changes: 43 additions & 7 deletions src/test/org/openscience/cdk/silent/IsotopeTest.java
@@ -1,9 +1,5 @@
/* $RCSfile$
* $Author$
* $Date$
* $Revision$
*
* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
/* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
* 2012 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
Expand All @@ -27,10 +23,10 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.interfaces.AbstractIsotopeTest;
import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.interfaces.IElement;
import org.openscience.cdk.interfaces.IIsotope;
import org.openscience.cdk.interfaces.AbstractIsotopeTest;
import org.openscience.cdk.interfaces.ITestObjectBuilder;

/**
Expand Down Expand Up @@ -82,6 +78,46 @@ public IChemObject newTestObject() {
Assert.assertEquals(80.0, i.getNaturalAbundance(), 0.001);
}

@Test public void testCompare_MassNumber() {
Isotope iso = new Isotope("C");
iso.setMassNumber(12);
Isotope iso2 = new Isotope("C");
iso2.setMassNumber((int)12.0);
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_MassNumberIntegers() {
Isotope iso = new Isotope("C");
iso.setMassNumber(new Integer(12));
Isotope iso2 = new Isotope("C");
iso2.setMassNumber(new Integer(12));
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_MassNumberIntegers_ValueOf() {
Isotope iso = new Isotope("C");
iso.setMassNumber(Integer.valueOf(12));
Isotope iso2 = new Isotope("C");
iso2.setMassNumber(Integer.valueOf(12));
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_ExactMass() {
Isotope iso = new Isotope("C");
iso.setExactMass(12.000000);
Isotope iso2 = new Isotope("C");
iso2.setExactMass(12.0);
Assert.assertTrue(iso.compare(iso2));
}

@Test public void testCompare_NaturalAbundance() {
Isotope iso = new Isotope("C");
iso.setNaturalAbundance(12.000000);
Isotope iso2 = new Isotope("C");
iso2.setNaturalAbundance(12.0);
Assert.assertTrue(iso.compare(iso2));
}

// Overwrite default methods: no notifications are expected!

@Test public void testNotifyChanged() {
Expand Down

0 comments on commit 46d48f9

Please sign in to comment.