Skip to content
Snippets Groups Projects
Commit acd989f8 authored by david's avatar david
Browse files

ajout des fonction slice -to -from

parent d55ac700
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.
......@@ -77,15 +77,26 @@ final public class Vector {
}
public Vector sliceFrom(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return slice (i,this.len());
}
public Vector sliceTo(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
return slice (0,i);
}
public Vector slice(int from, int to) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
Vector v =new Vector();
if (from>=to){
return v;
}
else{
for (double d : this.lstVector.subList(from,to))
{
v.lstVector.add(d);
}
return v;
}
}
public Vector removed(int i) {
......
......@@ -74,7 +74,7 @@ class VectorTest {
assertEquals(v.toString(), "Vector[1.0, 2.0, 3.0]");
assertEquals(v.t().toString(), "Transposed[1.0, 2.0, 3.0]");
}
/*
@Test
void vectorSlice() {
Vector v = Vector.of(1.0, 2.0, 3.0, 4.0, 5.0);
......@@ -83,8 +83,9 @@ class VectorTest {
assertEquals(v.slice(2,4), Vector.of(3.0, 4.0));
assertEquals(v.slice(4,4), Vector.empty());
assertEquals(v.slice(4,2), Vector.empty());
assertEquals(v.removed(2), Vector.of(1.0, 2.0, 4.0, 5.0));
// assertEquals(v.removed(2), Vector.of(1.0, 2.0, 4.0, 5.0));
}
/*
@Test
void vectorConcat() {
Vector v1 = Vector.of(1.0, 2.0, 3.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment