diff --git a/src/main/java/ch/hepia/numeric/Vector.java b/src/main/java/ch/hepia/numeric/Vector.java index c03fca952d724535b10059aa47d651192a524d83..80134cff58cfaf16557c7149b0bd7d3c8566e04f 100644 --- a/src/main/java/ch/hepia/numeric/Vector.java +++ b/src/main/java/ch/hepia/numeric/Vector.java @@ -35,10 +35,10 @@ final public class Vector { } public int len() { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + //throw new UnsupportedOperationException("This feature isn't implemented yet"); + return this.lstVector.size(); } - //assertEquals(v1.toString(), "Vector[1.0, 2.0, 3.0]"); - //assertEquals(v1.add(v2),v3); + public double get(int i) { throw new UnsupportedOperationException("This feature isn't implemented yet"); @@ -58,11 +58,23 @@ final public class Vector { } public Vector mul(double m) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + //throw new UnsupportedOperationException("This feature isn't implemented yet"); + Vector v = new Vector(); + for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element) + { + v.lstVector.add(this.lstVector.get(i)*m); + } + return v; } public Vector sub(Vector that) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + Vector v = new Vector(); + for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element) + { + v.lstVector.add(this.lstVector.get(i)-that.lstVector.get(i)); + } + return v; + //throw new UnsupportedOperationException("This feature isn't implemented yet"); } public double norm() { @@ -116,7 +128,9 @@ final public class Vector { } public static Vector empty() { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + Vector v = new Vector(); + return v; + //throw new UnsupportedOperationException("This feature isn't implemented yet"); } public static Vector fill(int nb, double value) { @@ -155,7 +169,7 @@ final public class Vector { // Apply formatting to the string if necessary strings.add(d.toString()); } - if(this instanceof Vector) + if(this instanceof ch.hepia.numeric.Vector) { return "Vector"+String.valueOf(strings); } @@ -166,8 +180,27 @@ final public class Vector { //throw new UnsupportedOperationException("This feature isn't implemented yet"); } +/* @Override public boolean equals(Object obj) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + + if(this instanceof ch.hepia.numeric.Vector) + { + for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element) + { + if(((Vector)obj).lstVector.get(i)!=this.lstVector.get(i)) + { + return false; + } + } + return true; + } + else + { + //a ecrire + return true; + } + //throw new UnsupportedOperationException("boolean This feature isn't implemented yet"); } +*/ } diff --git a/src/test/java/ch/hepia/numeric/AppTest.java b/src/test/java/ch/hepia/numeric/AppTest.java index 41b50e872c0459ce67747de68c8546797290716b..eb2ed6aa1a9f6fea2c8fe43c4bb256381e33e555 100644 --- a/src/test/java/ch/hepia/numeric/AppTest.java +++ b/src/test/java/ch/hepia/numeric/AppTest.java @@ -15,15 +15,13 @@ class VectorTest { Vector v1 = Vector.of(1.0, 2.0, 3.0); Vector v2 = Vector.of(-1.0, -2.0, -3.0); Vector v3 = Vector.of(-1.0, -2.0, -3.0); - v3=v1.add(v2); - System.out.println(v1.toString()); - System.out.println(v2.toString()); - System.out.println(v3.toString()); - //assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0)); - //assertEquals(v1.sub(v2), Vector.of(2.0, 4.0, 6.0)); - //assertEquals(v1.mul(3.0), Vector.of(3.0, 6.0, 9.0)); - //assertEquals(Vector.empty().len(), 0); - //assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3); + //Transposed t1= new Transposed(v2); + //System.out.println(v1.toString()); + assertEquals(v1.add(v2).toString(), Vector.of(0.0, 0.0, 0.0).toString()); + assertEquals(v1.sub(v2).toString(), Vector.of(2.0, 4.0, 6.0).toString()); + assertEquals(v1.mul(3.0).toString(), Vector.of(3.0, 6.0, 9.0).toString()); + assertEquals(Vector.empty().len(), 0); + assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3); } /* @Test @@ -68,6 +66,7 @@ class VectorTest { void vectorToString() { Vector v = Vector.of(1.0, 2.0, 3.0); assertEquals(v.toString(), "Vector[1.0, 2.0, 3.0]"); + //System.out.println(v.t().toString()); //assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]"); } /*