Skip to content
Snippets Groups Projects
Commit df19a236 authored by tanguy.dietrich's avatar tanguy.dietrich
Browse files

Ajout de add, mul, sub, len, et divers test...

parent 2fb9c55d
Branches
Tags
2 merge requests!2Tanguy,!1David
...@@ -35,10 +35,10 @@ final public class Vector { ...@@ -35,10 +35,10 @@ final public class Vector {
} }
public int len() { 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) { public double get(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); throw new UnsupportedOperationException("This feature isn't implemented yet");
...@@ -58,11 +58,23 @@ final public class Vector { ...@@ -58,11 +58,23 @@ final public class Vector {
} }
public Vector mul(double m) { 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) { 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() { public double norm() {
...@@ -116,7 +128,9 @@ final public class Vector { ...@@ -116,7 +128,9 @@ final public class Vector {
} }
public static Vector empty() { 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) { public static Vector fill(int nb, double value) {
...@@ -155,7 +169,7 @@ final public class Vector { ...@@ -155,7 +169,7 @@ final public class Vector {
// Apply formatting to the string if necessary // Apply formatting to the string if necessary
strings.add(d.toString()); strings.add(d.toString());
} }
if(this instanceof Vector) if(this instanceof ch.hepia.numeric.Vector)
{ {
return "Vector"+String.valueOf(strings); return "Vector"+String.valueOf(strings);
} }
...@@ -166,8 +180,27 @@ final public class Vector { ...@@ -166,8 +180,27 @@ final public class Vector {
//throw new UnsupportedOperationException("This feature isn't implemented yet"); //throw new UnsupportedOperationException("This feature isn't implemented yet");
} }
/*
@Override @Override
public boolean equals(Object obj) { 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");
} }
*/
} }
...@@ -15,15 +15,13 @@ class VectorTest { ...@@ -15,15 +15,13 @@ class VectorTest {
Vector v1 = Vector.of(1.0, 2.0, 3.0); Vector v1 = Vector.of(1.0, 2.0, 3.0);
Vector v2 = 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); Vector v3 = Vector.of(-1.0, -2.0, -3.0);
v3=v1.add(v2); //Transposed t1= new Transposed(v2);
System.out.println(v1.toString()); //System.out.println(v1.toString());
System.out.println(v2.toString()); assertEquals(v1.add(v2).toString(), Vector.of(0.0, 0.0, 0.0).toString());
System.out.println(v3.toString()); assertEquals(v1.sub(v2).toString(), Vector.of(2.0, 4.0, 6.0).toString());
//assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0)); assertEquals(v1.mul(3.0).toString(), Vector.of(3.0, 6.0, 9.0).toString());
//assertEquals(v1.sub(v2), Vector.of(2.0, 4.0, 6.0)); assertEquals(Vector.empty().len(), 0);
//assertEquals(v1.mul(3.0), Vector.of(3.0, 6.0, 9.0)); assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3);
//assertEquals(Vector.empty().len(), 0);
//assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3);
} }
/* /*
@Test @Test
...@@ -68,6 +66,7 @@ class VectorTest { ...@@ -68,6 +66,7 @@ class VectorTest {
void vectorToString() { void vectorToString() {
Vector v = Vector.of(1.0, 2.0, 3.0); Vector v = Vector.of(1.0, 2.0, 3.0);
assertEquals(v.toString(), "Vector[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]"); //assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]");
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment