|
4 | 4 | */ |
5 | 5 | package com.deepak.data.structures.Vector; |
6 | 6 |
|
| 7 | +import org.junit.Assert; |
| 8 | +import org.junit.Test; |
| 9 | + |
7 | 10 | /** |
8 | 11 | * Test cases for custom vector |
9 | 12 | * |
10 | 13 | * @author Deepak |
11 | 14 | */ |
12 | 15 | public class CustomVectorTest { |
13 | 16 |
|
14 | | - |
| 17 | +/** |
| 18 | + * Test case for vector creation when no capacity is defined |
| 19 | + */ |
| 20 | +@Test |
| 21 | +public void testVecorCreationWhenNoCapacityIsDefined() { |
| 22 | +CustomVector<String> vector = new CustomVector<>(); |
| 23 | +Assert.assertEquals(vector.capacity(), 10); |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * Test case for vector creation when capacity is defined |
| 28 | + */ |
| 29 | +@Test |
| 30 | +public void testVectorCreationWhenCapacityIsDefined() { |
| 31 | +CustomVector<String> vector = new CustomVector<>(3); |
| 32 | +Assert.assertEquals(vector.capacity(), 3); |
| 33 | +vector.addElement("A"); |
| 34 | +vector.addElement("B"); |
| 35 | +vector.addElement("C"); |
| 36 | +vector.addElement("D"); |
| 37 | +/* When 4th element is added, capacity should double |
| 38 | + * since we have not specified increment capacity */ |
| 39 | +Assert.assertEquals(vector.capacity(), 6); |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * Test case for vector creation when capacity increases |
| 44 | + * and increment capacity is defined |
| 45 | + */ |
| 46 | +@Test |
| 47 | +public void testVectorCreationWhenCapacityIncreases() { |
| 48 | +CustomVector<String> vector = new CustomVector<>(3, 10); |
| 49 | +Assert.assertEquals(vector.capacity(), 3); |
| 50 | +vector.addElement("A"); |
| 51 | +vector.addElement("B"); |
| 52 | +vector.addElement("C"); |
| 53 | +vector.addElement("D"); |
| 54 | +/* When 4th element is added, capacity should increase |
| 55 | + * taking into consideration, the increment capacity */ |
| 56 | +Assert.assertEquals(vector.capacity(), 13); |
| 57 | +} |
15 | 58 | } |
0 commit comments