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

Ajout de Structure et Optimisation de vector+ correction de Assert par David et Tanguy

parent 5c52644f
Branches
Tags untagged-942bdedb39bd9d9a9db2
2 merge requests!2Tanguy,!1David
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
...@@ -14,13 +14,6 @@ final public class Vector { ...@@ -14,13 +14,6 @@ final public class Vector {
} }
private Vector(Double... elements) { private Vector(Double... elements) {
this.lstVector=new ArrayList<Double>();
for(double e:elements)
{
lstVector.add(e);
}
}
private Vector(List<Double> elements) {
this.lstVector=new ArrayList<Double>(); this.lstVector=new ArrayList<Double>();
for(double e:elements) for(double e:elements)
{ {
...@@ -28,6 +21,10 @@ final public class Vector { ...@@ -28,6 +21,10 @@ final public class Vector {
} }
} }
private Vector(List<Double> elements) {
this.lstVector=elements;
}
public Transposed t() { public Transposed t() {
return new Transposed(this); return new Transposed(this);
} }
...@@ -54,9 +51,9 @@ final public class Vector { ...@@ -54,9 +51,9 @@ final public class Vector {
public Vector mul(double m) { public Vector mul(double m) {
Vector v = new Vector(); Vector v = new Vector();
for(int i=0;i<this.len();i++) for(double e:this.lstVector)
{ {
v.lstVector.add(this.get(i)*m); v.lstVector.add(e*m);
} }
return v; return v;
} }
...@@ -71,14 +68,12 @@ final public class Vector { ...@@ -71,14 +68,12 @@ final public class Vector {
} }
public double norm() { public double norm() {
double norme=0;
double power=0; double power=0;
for(int i=0;i<this.len();i++) for(double e:this.lstVector)
{ {
power=power +(this.get(i)*this.get(i)); power+=(e*e);
} }
norme=Math.sqrt(power); return Math.sqrt(power);
return norme;
} }
public Vector sliceFrom(int i) { public Vector sliceFrom(int i) {
...@@ -114,26 +109,16 @@ final public class Vector { ...@@ -114,26 +109,16 @@ final public class Vector {
} }
public static Vector of(Double... elements) { public static Vector of(Double... elements) {
Vector v = new Vector(); return new Vector(elements);
for(double e:elements)
{
v.lstVector.add(e);
}
return v;
} }
public static Vector of(List<Double> elements) { public static Vector of(List<Double> elements) {
Vector v = new Vector(); return new Vector(elements);
for(double e:elements)
{
v.lstVector.add(e);
}
return v;
} }
public static Vector empty() { public static Vector empty() {
Vector v = new Vector(); // Vector v = new Vector();
return v; return new Vector();
} }
public static Vector fill(int nb, double value) { public static Vector fill(int nb, double value) {
...@@ -195,15 +180,14 @@ final public class Vector { ...@@ -195,15 +180,14 @@ final public class Vector {
return "Vector"+String.valueOf(strings); return "Vector"+String.valueOf(strings);
} }
/*
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof Vector)
if(this instanceof ch.hepia.numeric.Vector)
{ {
for(int i=0;i<this.lstVector.size();i++) for(int i=0;i<this.lstVector.size();i++)
{ {
if(((Vector)obj).lstVector.get(i)!=this.lstVector.get(i)) if(((Vector)obj).get(i)!=this.get(i))
{ {
return false; return false;
} }
...@@ -213,9 +197,8 @@ final public class Vector { ...@@ -213,9 +197,8 @@ final public class Vector {
else else
{ {
//a ecrire //a ecrire
return true; return false;
} }
//throw new UnsupportedOperationException("boolean This feature isn't implemented yet"); //throw new UnsupportedOperationException("boolean This feature isn't implemented yet");
} }
*/
} }
package ch.hepia.structure;
import java.util.List;
import java.util.ArrayList;
import java.util.function.DoubleFunction;
import java.util.function.Function;
final public class BinaryHeap {
private BinaryHeap() {
}
}
...@@ -15,10 +15,14 @@ class VectorTest { ...@@ -15,10 +15,14 @@ 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);
//assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0)); Vector v4 = Vector.of(-50.0, -2.0, -3.0);
assertEquals(v1.add(v2), Vector.of(0.0, 0.0, 0.0));
assertEquals(v1.add(v2).toString(), Vector.of(0.0, 0.0, 0.0).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.sub(v2).toString(), Vector.of(2.0, 4.0, 6.0).toString());
assertEquals(v4.sub(v3), Vector.of(-49.0, 0.0, 0.0));
assertEquals(v1.mul(3.0).toString(), Vector.of(3.0, 6.0, 9.0).toString()); assertEquals(v1.mul(3.0).toString(), Vector.of(3.0, 6.0, 9.0).toString());
assertEquals(v1.mul(-0.0).toString(), Vector.of(-0.0, -0.0, -0.0).toString());
assertEquals(v1.mul(0.0).toString(), Vector.of(0.0, 0.0, 0.0).toString());
assertEquals(Vector.empty().len(), 0); assertEquals(Vector.empty().len(), 0);
assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3); assertEquals(Vector.of(1.0, 2.0, 1.0).len(), 3);
} }
...@@ -26,6 +30,7 @@ class VectorTest { ...@@ -26,6 +30,7 @@ class VectorTest {
@Test @Test
void vectorCreation() { void vectorCreation() {
assertEquals(Vector.zeros(3).toString(), Vector.of(0.0, 0.0, 0.0).toString()); assertEquals(Vector.zeros(3).toString(), Vector.of(0.0, 0.0, 0.0).toString());
assertEquals(Vector.zeros(10000).len(), 10000);
//assertEquals(Vector.zeros(3), Vector.of(0.0, 0.0, 0.0)); //assertEquals(Vector.zeros(3), Vector.of(0.0, 0.0, 0.0));
//assertEquals(Vector.ones(3), Vector.of(1.0, 1.0, 1.0)); //assertEquals(Vector.ones(3), Vector.of(1.0, 1.0, 1.0));
//assertEquals(Vector.of(1.0, 2.0).map( d -> d * 2.0), Vector.of(2.0, 4.0)); //assertEquals(Vector.of(1.0, 2.0).map( d -> d * 2.0), Vector.of(2.0, 4.0));
......
package ch.hepia.structure;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
class BinaryHeapTest
{
@Test
void BinaryHeapMainOperations() {
assertEquals(1,1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment