Author: nick
Date: Tue Apr 15 16:34:27 2008
New Revision: 648456

URL: http://svn.apache.org/viewvc?rev=648456&view=rev
Log:
Update the build to fetch junit on demand, and add first bit of code

Added:
    commons/sandbox/me/trunk/src/org/
    commons/sandbox/me/trunk/src/org/apache/
    commons/sandbox/me/trunk/src/org/apache/commons/
    commons/sandbox/me/trunk/src/org/apache/commons/me/
    commons/sandbox/me/trunk/src/org/apache/commons/me/math/   (with props)
    commons/sandbox/me/trunk/src/org/apache/commons/me/util/   (with props)
    commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java   
(with props)
    commons/sandbox/me/trunk/test-src/org/
    commons/sandbox/me/trunk/test-src/org/apache/
    commons/sandbox/me/trunk/test-src/org/apache/commons/
    commons/sandbox/me/trunk/test-src/org/apache/commons/me/
    commons/sandbox/me/trunk/test-src/org/apache/commons/me/math/   (with props)
    commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/   (with props)
    
commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java
   (with props)
Removed:
    commons/sandbox/me/trunk/build-lib/junit-3.8.1.jar
Modified:
    commons/sandbox/me/trunk/build.xml

Modified: commons/sandbox/me/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/commons/sandbox/me/trunk/build.xml?rev=648456&r1=648455&r2=648456&view=diff
==============================================================================
--- commons/sandbox/me/trunk/build.xml (original)
+++ commons/sandbox/me/trunk/build.xml Tue Apr 15 16:34:27 2008
@@ -117,13 +117,17 @@
        </path>
 
 
+       <property name="repository" value="http://www.ibiblio.org/maven"/>
+       <property name="junit.jar1.dir" location="build-lib/junit-3.8.1.jar"/>
+       <property name="junit.jar1.url" 
value="${repository}/junit/jars/junit-3.8.1.jar"/>
+
 
        <!-- ******************************************** -->
        <!--  Core setup tasks                            -->
        <!-- ******************************************** -->
 
        <!-- Ensure that all the directories we need exist -->
-       <target name="init">
+       <target name="init" depends="check-jars,fetch-jars">
                <mkdir dir="build"/>
                <mkdir dir="build/ant-classes"/>
                <mkdir dir="build/mobile-classes"/>
@@ -131,6 +135,17 @@
                <mkdir dir="build/dist"/>
                <mkdir dir="build/tests"/>
                <mkdir dir="build/ide-classes"/>
+       </target>
+
+       <!-- Ensure all jars we need are found -->
+       <target name="check-jars">
+               <condition property="junit.present">
+                       <available file="${junit.jar1.dir}"/>
+               </condition>
+       </target>
+       <target name="fetch-jars" depends="fetch-junit" />
+       <target name="fetch-junit" unless="junit.present">
+               <get src="${junit.jar1.url}" dest="${junit.jar1.dir}"/>
        </target>
 
        <!-- Delete all jars, and compiled classes -->

Propchange: commons/sandbox/me/trunk/src/org/apache/commons/me/math/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 15 16:34:27 2008
@@ -0,0 +1,2 @@
+*.swp
+*.class

Propchange: commons/sandbox/me/trunk/src/org/apache/commons/me/util/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 15 16:34:27 2008
@@ -0,0 +1,2 @@
+*.swp
+*.class

Added: commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java?rev=648456&view=auto
==============================================================================
--- commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java 
(added)
+++ commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java 
Tue Apr 15 16:34:27 2008
@@ -0,0 +1,34 @@
+package org.apache.commons.me.util;
+
+/**
+ * Array related helper methods
+ */
+public class ArrayHelper {
+       public static boolean equals(int[] a, int[] b) {
+               if(a == null || b == null) { return false; }
+               if(a.length != b.length) { return false; }
+               for(int i=0; i<a.length; i++) {
+                       if(a[i] != b[i]) { return false; }
+               }
+               return true;
+       }
+       public static boolean equals(float[] a, float[] b) {
+               if(a == null || b == null) { return false; }
+               if(a.length != b.length) { return false; }
+               for(int i=0; i<a.length; i++) {
+                       if(a[i] != b[i]) { return false; }
+               }
+               return true;
+       }
+       public static boolean equals(double[] a, double[] b) {
+               if(a == null || b == null) { return false; }
+               if(a.length != b.length) { return false; }
+               for(int i=0; i<a.length; i++) {
+                       // We want within 0.001%
+                       double delta = Math.abs(a[i]-b[i]);
+                       double rel_delta = delta / a[i] * 100;
+                       if(rel_delta > 0.001) { return false; }
+               }
+               return true;
+       }
+}

Propchange: 
commons/sandbox/me/trunk/src/org/apache/commons/me/util/ArrayHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/me/trunk/test-src/org/apache/commons/me/math/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 15 16:34:27 2008
@@ -0,0 +1,2 @@
+*.class
+*.swp

Propchange: commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 15 16:34:27 2008
@@ -0,0 +1,2 @@
+*.swp
+*.class

Added: 
commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java?rev=648456&view=auto
==============================================================================
--- 
commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java
 (added)
+++ 
commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java
 Tue Apr 15 16:34:27 2008
@@ -0,0 +1,134 @@
+/* ====================================================================
+   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.me.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the Array Helper
+ */
+public class TestArrayHelper extends TestCase {
+       public void testEqualsInts() {
+               assertFalse(
+                               ArrayHelper.equals(new int[0], null)
+               );
+               assertFalse(
+                               ArrayHelper.equals(new int[0], new int[1])
+               );
+               assertFalse(
+                               ArrayHelper.equals(new int[] { 1, 2 }, new 
int[] { 1 })
+               );
+               assertFalse(
+                               ArrayHelper.equals(new int[] { 1, 2 }, new 
int[] { 1,3 })
+               );
+               
+               assertTrue(
+                               ArrayHelper.equals(new int[0], new int[0])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new int[1], new int[1])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new int[] { 1 }, new int[] { 
1 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new int[] { 1,5,6 }, new 
int[] { 1,5,6 })
+               );
+       }
+
+       public void testEqualsFloats() {
+               assertFalse(
+                               ArrayHelper.equals(new float[0], null)
+               );
+               assertFalse(
+                               ArrayHelper.equals(new float[0], new float[1])
+               );
+               assertFalse(
+                               ArrayHelper.equals(new float[] { 1, 2 }, new 
float[] { 1 })
+               );
+               assertFalse(
+                               ArrayHelper.equals(new float[] { 1, 2 }, new 
float[] { 1,3 })
+               );
+               
+               assertTrue(
+                               ArrayHelper.equals(new float[0], new float[0])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new float[1], new float[1])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new float[] { 1 }, new 
float[] { 1 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new float[] { 1.66f }, new 
float[] { 1.66f })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new float[] { 1,5,6 }, new 
float[] { 1,5,6 })
+               );
+       }
+
+       public void testEqualsDoubles() {
+               assertFalse(
+                               ArrayHelper.equals(new double[0], null)
+               );
+               assertFalse(
+                               ArrayHelper.equals(new double[0], new double[1])
+               );
+               assertFalse(
+                               ArrayHelper.equals(new double[] { 1, 2 }, new 
double[] { 1 })
+               );
+               assertFalse(
+                               ArrayHelper.equals(new double[] { 1, 2 }, new 
double[] { 1,3 })
+               );
+               
+               assertTrue(
+                               ArrayHelper.equals(new double[0], new double[0])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[1], new double[1])
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1 }, new 
double[] { 1 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.66f }, new 
double[] { 1.66f })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.66 }, new 
double[] { 1.66 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1,5,6 }, new 
double[] { 1,5,6 })
+               );
+               
+               // Must be within 0.001%
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.66000001 }, 
new double[] { 1.66000002 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.6600001 }, 
new double[] { 1.6600002 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.660001 }, 
new double[] { 1.660002 })
+               );
+               assertTrue(
+                               ArrayHelper.equals(new double[] { 1.66001 }, 
new double[] { 1.66002 })
+               );
+               assertFalse(
+                               ArrayHelper.equals(new double[] { 1.6601 }, new 
double[] { 1.6602 })
+               );
+       }
+}

Propchange: 
commons/sandbox/me/trunk/test-src/org/apache/commons/me/util/TestArrayHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to