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

Correction du Vector.add()

parent caf65694
No related branches found
No related tags found
2 merge requests!2Tanguy,!1David
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
......@@ -7,11 +7,12 @@ import java.util.function.Function;
final public class Vector {
private static List<Double> lstVector;// = new ArrayList<Double>();
private List<Double> lstVector;// = new ArrayList<Double>();
private Vector() {
this.lstVector=new ArrayList<Double>();
}
private Vector(Double... elements) {
this.lstVector=new ArrayList<Double>();
for(double e:elements)
......@@ -36,6 +37,8 @@ final public class Vector {
public int len() {
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
//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");
......@@ -46,11 +49,12 @@ final public class Vector {
public Vector add(Vector that) {
//throw new UnsupportedOperationException("This feature isn't implemented yet");
for(double e:that.lstVector)
Vector v = new Vector();
for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element)
{
this.lstVector.add(e);
v.lstVector.add(Double.sum(this.lstVector.get(i),that.lstVector.get(i)));
}
return this;
return v;
}
public Vector mul(double m) {
......@@ -151,7 +155,14 @@ final public class Vector {
// Apply formatting to the string if necessary
strings.add(d.toString());
}
return "Vector"+String.valueOf(strings);
if(this instanceof Vector)
{
return "Vector"+String.valueOf(strings);
}
else
{
return "Transposed"+String.valueOf(strings);
}
//throw new UnsupportedOperationException("This feature isn't implemented yet");
}
......
......@@ -14,8 +14,11 @@ class VectorTest {
void vectorMainOperations() {
Vector v1 = Vector.of(1.0, 2.0, 3.0);
Vector v2 = Vector.of(-1.0, -2.0, -3.0);
//System.out.println(v2.toString());
//v2 = v1.add(v2);
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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment