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
No related branches found
No related tags found
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 {
}
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>();
for(double e:elements)
{
......@@ -28,6 +21,10 @@ final public class Vector {
}
}
private Vector(List<Double> elements) {
this.lstVector=elements;
}
public Transposed t() {
return new Transposed(this);
}
......@@ -54,9 +51,9 @@ final public class Vector {
public Vector mul(double m) {
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;
}
......@@ -71,14 +68,12 @@ final public class Vector {
}
public double norm() {
double norme=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 norme;
return Math.sqrt(power);
}
public Vector sliceFrom(int i) {
......@@ -114,26 +109,16 @@ final public class Vector {
}
public static Vector of(Double... elements) {
Vector v = new Vector();
for(double e:elements)
{
v.lstVector.add(e);
}
return v;
return new Vector(elements);
}
public static Vector of(List<Double> elements) {
Vector v = new Vector();
for(double e:elements)
{
v.lstVector.add(e);
}
return v;
return new Vector(elements);
}
public static Vector empty() {
Vector v = new Vector();
return v;
// Vector v = new Vector();
return new Vector();
}
public static Vector fill(int nb, double value) {
......@@ -195,15 +180,14 @@ final public class Vector {
return "Vector"+String.valueOf(strings);
}
/*
@Override
public boolean equals(Object obj) {
if(this instanceof ch.hepia.numeric.Vector)
if(obj instanceof Vector)
{
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;
}
......@@ -213,9 +197,8 @@ final public class Vector {
else
{
//a ecrire
return true;
return false;
}
//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 {
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);
//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.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(-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.of(1.0, 2.0, 1.0).len(), 3);
}
......@@ -26,6 +30,7 @@ class VectorTest {
@Test
void vectorCreation() {
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.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));
......
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