Skip to content
Snippets Groups Projects
Commit af9d6d78 authored by fefe's avatar fefe
Browse files

New function fill , tested

parent 9ef4a655
No related branches found
No related tags found
No related merge requests found
......@@ -189,7 +189,27 @@ final public class Vector {
public static double norms(List<Vector> vs) {
return Vector.sum(vs).norm();
}
// FILL NEW VERSION :
public static SubVec fill(int nbr){
return new Vector().new SubVec(nbr);
}
protected class SubVec{
private int nbre;
protected SubVec(int nbre){
this.nbre = nbre;
}
private int getNbre(){
return this.nbre;
}
public Vector withValue(Double alpha){
List<Double> newVec = new ArrayList<>();
for (int i = 0; i < this.getNbre();i++){
newVec.add(alpha);
}
return new Vector(newVec);
}
}
@Override
public String toString() {
......
......@@ -137,4 +137,11 @@ class VectorTest {
assertEquals(v.slice(4,2), Transposed.empty());
assertEquals(v.removed(2), Transposed.of(1.0, 2.0, 4.0, 5.0));
}
// Vector V2 functions test :
@Test
void vectorfillv2() {
assertEquals(Vector.fill(3).withValue(1.7), Vector.of(1.7, 1.7, 1.7));
assertEquals(Vector.fill(4).withValue(1.5), Vector.of(1.5, 1.5, 1.5, 1.5));
assertEquals(Vector.fill(2).withValue(1.0), Vector.of(1.0, 1.0));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment