public void CostaSoaresTest() { // Exact same order should produce 1.0 Statistics stat1 = new Statistics(new[] { 1.0, 2, 3, 4 }); Statistics stat2 = new Statistics(new[] { 1.0, 2, 3, 4 }); Assert.AreEqual(1.0, stat1.CostaSoares(stat2)); // Same order but differing intensities should also produce 1.0, // since this is a rank correlation stat2 = new Statistics(new[] { 5.0, 6, 7, 8 }); Assert.AreEqual(1.0, stat1.CostaSoares(stat2)); // Flipping the order of larger numbers should yeild a lower score // than flipping smaller numbers stat2 = new Statistics(new[] { 1.0, 2, 4, 3 }); double cs1 = stat1.CostaSoares(stat2); stat2 = new Statistics(new[] { 2.0, 1, 3, 4 }); double cs2 = stat1.CostaSoares(stat2); Assert.IsTrue(cs1 < cs2); // Swapping highest rank with lowest should be even worse stat2 = new Statistics(new[] { 4.0, 2, 3, 1 }); Assert.IsTrue(stat1.CostaSoares(stat2) < cs1); // Two same ranked should have less impact than flipping stat2 = new Statistics(new[] { 1.0, 1, 3, 4 }); double cs3 = stat1.CostaSoares(stat2); Assert.IsTrue(cs2 <= cs3); // Well, actually it appears to yield 1.0, which seems broken // Assert.AreEqual(1.0, cs3); // Try the same thing with 1 and 2 rankings stat2 = new Statistics(new[] { 1.0, 2, 3, 3.0 }); cs3 = stat1.CostaSoares(stat2); Assert.IsTrue(cs1 <= cs3); // Again this yields 1.0, which seems more broken // Assert.AreEqual(1.0, cs3); // Try everything equal // stat2 = new Statistics(new[] { 1.0, 1, 1, 1 }); // cs3 = stat1.CostaSoares(stat2); // Wow! 1.0 again. Now that seems really broken // Assert.AreEqual(1.0, cs3); // Reversing the order should yield -1 stat2 = new Statistics(new[] { 4.0, 3, 2, 1 }); Assert.AreEqual(-1.0, stat1.CostaSoares(stat2)); // Reordering smaller numbers below the top 4 should have no impact stat1 = new Statistics(new[] { 1.0, 2, 3, 4, 5, 6, 7, 8 }); stat2 = new Statistics(new[] { 2.0, 1, 4, 3, 5, 6, 7, 8 }); cs3 = stat1.CostaSoares(stat2, 4); Assert.AreEqual(1.0, cs3); cs3 = stat1.CostaSoares(stat2); Assert.IsTrue(cs3 > 0.95); // All same intensity of lower ranked numbers should also have no impact stat2 = new Statistics(new[] { 0.0, 0, 0, 0, 5, 6, 7, 8 }); cs3 = stat1.CostaSoares(stat2, 4); Assert.AreEqual(1.0, cs3); // And some similar tests of negative correlation stat2 = new Statistics(new[] { 8.0, 7, 6, 5, 0, 0, 0, 0 }); cs3 = stat1.CostaSoares(stat2, 4); Assert.AreEqual(-1.0, cs3); stat2 = new Statistics(new[] { 8.0, 7, 6, 5, 4, 3, 0, 0 }); cs3 = stat1.CostaSoares(stat2, 4); Assert.AreEqual(-1.0, cs3); stat2 = new Statistics(new[] { 8.0, 7, 6, 5, 4, 3, 2, 1 }); cs3 = stat1.CostaSoares(stat2); Assert.AreEqual(-1.0, cs3); // And perhaps the most broken thing of all, just having the most // intense peak in the right place for a set of 8 gives you 1.0 // But this works with more recent fixes. stat2 = new Statistics(new[] { 0.0, 0, 0, 0, 0, 0, 0, 8 }); cs3 = stat1.CostaSoares(stat2); Assert.IsTrue(cs3 < 0); // But swapping highest and lowest should still be worse than // swapping second highest and second lowest. stat2 = new Statistics(new[] { 8.0, 2, 3, 4, 5, 6, 7, 1 }); cs1 = stat1.CostaSoares(stat2); stat2 = new Statistics(new[] { 1.0, 7.0, 3, 4, 5, 6, 2, 8 }); cs2 = stat1.CostaSoares(stat2); Assert.IsTrue(cs1 < cs2); }