Skip to content

Commit cc467b0

Browse files
authored
Merge pull request #138 from cryptimeleon/bugfix/vector-concatenate
Fix concatenation.
2 parents 65d16d5 + 775ed70 commit cc467b0

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/main/java/org/cryptimeleon/math/structures/cartesian/Vector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public Vector<X> truncate(int newLength) {
329329
public Vector<X> concatenate(Vector<? extends X> secondPart) {
330330
ArrayList<X> result = new ArrayList<>(values.size() + secondPart.values.size());
331331
result.addAll(values);
332-
result.add((X) secondPart.values);
332+
result.addAll(secondPart.values);
333333

334334
return instantiateWithSafeArray(result);
335335
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.cryptimeleon.math.structures;
2+
3+
import org.cryptimeleon.math.structures.cartesian.Vector;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
public class VectorTests {
9+
10+
/**
11+
* Test that concatenation yields the correct result.
12+
*/
13+
@Test
14+
void testConcatenation() {
15+
Vector<Integer> firstVector = Vector.of(0, 1, 2, 3);
16+
Vector<Integer> secondVector = Vector.of(4, 5, 6);
17+
Vector<Integer> concatenation = firstVector.concatenate(secondVector);
18+
19+
assertEquals(concatenation.length(), firstVector.length() + secondVector.length());
20+
for (int i = 0; i < concatenation.length(); i++)
21+
assertEquals(concatenation.get(i), i);
22+
}
23+
}

0 commit comments

Comments
 (0)