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

Ajout de Zeros, et modification de memo

parent df19a236
No related branches found
No related tags found
1 merge request!2Tanguy
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
recupere l'etat actuel du projet a partir de git recupere l'etat actuel du projet a partir de git
>git clone https://githepia.hesge.ch/david.carballo/poo2019numeric >git clone https://githepia.hesge.ch/david.carballo/poo2019numeric
Changement de branche
>git checkout -b NomBranche
ajoute les nouvelle modification ajoute les nouvelle modification
>git add . >git add .
...@@ -13,5 +16,5 @@ modifie le git ...@@ -13,5 +16,5 @@ modifie le git
AUTRE : AUTRE :
verifie si il y a des changement verifie si il y a des changement
>git diff >git diff
\ No newline at end of file
...@@ -124,7 +124,13 @@ final public class Vector { ...@@ -124,7 +124,13 @@ final public class Vector {
} }
public static Vector of(List<Double> elements) { public static Vector of(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); //throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v = new Vector();
for(double e:elements)
{
v.lstVector.add(e);
}
return v;
} }
public static Vector empty() { public static Vector empty() {
...@@ -138,7 +144,13 @@ final public class Vector { ...@@ -138,7 +144,13 @@ final public class Vector {
} }
public static Vector zeros(int nb) { public static Vector zeros(int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); Vector v = new Vector();
for(int i=0;i<nb;i++)
{
v.lstVector.add(0.0);
}
return v;
//throw new UnsupportedOperationException("This feature isn't implemented yet");
} }
public static Vector ones(int nb) { public static Vector ones(int nb) {
...@@ -183,7 +195,6 @@ final public class Vector { ...@@ -183,7 +195,6 @@ final public class Vector {
/* /*
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(this instanceof ch.hepia.numeric.Vector) if(this instanceof ch.hepia.numeric.Vector)
{ {
for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element) for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element)
......
...@@ -17,26 +17,29 @@ class VectorTest { ...@@ -17,26 +17,29 @@ class VectorTest {
Vector v3 = Vector.of(-1.0, -2.0, -3.0); Vector v3 = Vector.of(-1.0, -2.0, -3.0);
//Transposed t1= new Transposed(v2); //Transposed t1= new Transposed(v2);
//System.out.println(v1.toString()); //System.out.println(v1.toString());
//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(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(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);
} }
/*
@Test @Test
void vectorCreation() { void vectorCreation() {
assertEquals(Vector.zeros(3), Vector.of(0.0, 0.0, 0.0)); assertEquals(Vector.zeros(3).toString(), Vector.of(0.0, 0.0, 0.0).toString());
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));
assertEquals(Vector.fill(3, 1.7), Vector.of(1.7, 1.7, 1.7)); //assertEquals(Vector.fill(3, 1.7), Vector.of(1.7, 1.7, 1.7));
assertEquals(Vector.tabulate(4, i -> i*5.0), Vector.of(0.0, 5.0, 10.0, 15.0)); //assertEquals(Vector.tabulate(4, i -> i*5.0), Vector.of(0.0, 5.0, 10.0, 15.0));
} }
/*
@Test @Test
void vectorLinespace() { void vectorLinespace() {
assertEquals(Vector.linespace(0.0, 1.0, 3), Vector.of(0.0, 0.5, 1.0)); assertEquals(Vector.linespace(0.0, 1.0, 3), Vector.of(0.0, 0.5, 1.0));
assertEquals(Vector.linespace(0.0, 1.0, 5), Vector.of(0.0, 0.25, 0.5, 0.75, 1.0)); assertEquals(Vector.linespace(0.0, 1.0, 5), Vector.of(0.0, 0.25, 0.5, 0.75, 1.0));
} }
@Test @Test
void vectorNormAndSum() { void vectorNormAndSum() {
assertEquals(Vector.of(1.0, 2.0, 2.0).norm(), 3.0); assertEquals(Vector.of(1.0, 2.0, 2.0).norm(), 3.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment