You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/07/20 22:13:25 UTC

svn commit: r795984 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java

Author: luc
Date: Mon Jul 20 20:13:24 2009
New Revision: 795984

URL: http://svn.apache.org/viewvc?rev=795984&view=rev
Log:
checked serialization of EuclideanIntegerPoint and added a tests suite for the class

Added:
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java   (with props)
Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java?rev=795984&r1=795983&r2=795984&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPoint.java Mon Jul 20 20:13:24 2009
@@ -28,8 +28,6 @@
  * @since 2.0
  */
 public class EuclideanIntegerPoint implements Clusterable<EuclideanIntegerPoint>, Serializable {
-    // TODO: Add Serializable documentation
-    // TODO: Check Serializable implementation
 
     /** Serializable version identifier. */
     private static final long serialVersionUID = 3946024775784901369L;

Added: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java?rev=795984&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java (added)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java Mon Jul 20 20:13:24 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.stat.clustering;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.math.TestUtils;
+import org.junit.Test;
+
+public class EuclideanIntegerPointTest {
+
+    @Test
+    public void testArrayIsReference() {
+        int[] array = { -3, -2, -1, 0, 1 };
+        assertTrue(array == new EuclideanIntegerPoint(array).getPoint());
+    }
+    
+    @Test
+    public void testDistance() {
+        EuclideanIntegerPoint e1 = new EuclideanIntegerPoint(new int[] { -3, -2, -1, 0, 1 });
+        EuclideanIntegerPoint e2 = new EuclideanIntegerPoint(new int[] {  1,  0, -1, 1, 1 });
+        assertEquals(Math.sqrt(21.0), e1.distanceFrom(e2), 1.0e-15);
+        assertEquals(0.0, e1.distanceFrom(e1), 1.0e-15);
+        assertEquals(0.0, e2.distanceFrom(e2), 1.0e-15);
+    }
+    
+    @Test
+    public void testCentroid() {
+        List<EuclideanIntegerPoint> list = new ArrayList<EuclideanIntegerPoint>();
+        list.add(new EuclideanIntegerPoint(new int[] {  1,  3 }));
+        list.add(new EuclideanIntegerPoint(new int[] {  2,  2 }));
+        list.add(new EuclideanIntegerPoint(new int[] {  3,  3 }));
+        list.add(new EuclideanIntegerPoint(new int[] {  2,  4 }));
+        EuclideanIntegerPoint c = list.get(0).centroidOf(list);
+        assertEquals(2, c.getPoint()[0]);
+        assertEquals(3, c.getPoint()[1]);
+    }
+    
+    @Test
+    public void testSerial() {
+        EuclideanIntegerPoint p = new EuclideanIntegerPoint(new int[] { -3, -2, -1, 0, 1 });
+        assertEquals(p, TestUtils.serializeAndRecover(p));
+    }
+    
+}

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision