-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checked serialization of EuclideanIntegerPoint and added a tests suit…
…e for the class git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@795984 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Luc Maisonobe
committed
Jul 20, 2009
1 parent
4cf9d99
commit bf74063
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |