cleanup work
This commit is contained in:
@@ -10,8 +10,7 @@ import org.junit.Test;
|
||||
public class CourseServiceTest {
|
||||
|
||||
@Test
|
||||
public void givenCourse_whenSetValuesUsingPropertyUtil_thenReturnSetValues()
|
||||
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
public void givenCourse_whenSetValuesUsingPropertyUtil_thenReturnSetValues() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
Course course = new Course();
|
||||
String name = "Computer Science";
|
||||
List<String> codes = Arrays.asList("CS", "CS01");
|
||||
@@ -36,8 +35,7 @@ public class CourseServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCopyProperties_whenCopyCourseToCourseEntity_thenCopyPropertyWithSameName()
|
||||
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
public void givenCopyProperties_whenCopyCourseToCourseEntity_thenCopyPropertyWithSameName() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
Course course = new Course();
|
||||
course.setName("Computer Science");
|
||||
course.setCodes(Arrays.asList("CS"));
|
||||
|
||||
+4
-6
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.commons.collections;
|
||||
|
||||
|
||||
import com.baeldung.commons.collectionutil.Address;
|
||||
import com.baeldung.commons.collectionutil.Customer;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -21,7 +20,6 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CollectionUtilsGuideTest {
|
||||
|
||||
|
||||
Customer customer1 = new Customer(1, "Daniel", 123456l, "locality1", "city1", "1234");
|
||||
Customer customer4 = new Customer(4, "Bob", 456789l, "locality4", "city4", "4567");
|
||||
List<Customer> list1, list2, list3, linkedList1;
|
||||
@@ -77,8 +75,8 @@ public class CollectionUtilsGuideTest {
|
||||
}
|
||||
});
|
||||
|
||||
//filterInverse does the opposite. It removes the element from the list if the Predicate returns true
|
||||
//select and selectRejected work the same way except that they do not remove elements from the given collection and return a new collection
|
||||
// filterInverse does the opposite. It removes the element from the list if the Predicate returns true
|
||||
// select and selectRejected work the same way except that they do not remove elements from the given collection and return a new collection
|
||||
|
||||
assertTrue(isModified && linkedList1.size() == 2);
|
||||
}
|
||||
@@ -88,8 +86,8 @@ public class CollectionUtilsGuideTest {
|
||||
List<Customer> emptyList = new ArrayList<>();
|
||||
List<Customer> nullList = null;
|
||||
|
||||
//Very handy at times where we want to check if a collection is not null and not empty too.
|
||||
//isNotEmpty does the opposite. Handy because using ! operator on isEmpty makes it missable while reading
|
||||
// Very handy at times where we want to check if a collection is not null and not empty too.
|
||||
// isNotEmpty does the opposite. Handy because using ! operator on isEmpty makes it missable while reading
|
||||
assertTrue(CollectionUtils.isNotEmpty(list1));
|
||||
assertTrue(CollectionUtils.isEmpty(nullList));
|
||||
assertTrue(CollectionUtils.isEmpty(emptyList));
|
||||
|
||||
@@ -27,16 +27,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MapUtilsTest {
|
||||
|
||||
private String[][] color2DArray = new String[][]{
|
||||
{"RED", "#FF0000"},
|
||||
{"GREEN", "#00FF00"},
|
||||
{"BLUE", "#0000FF"}
|
||||
};
|
||||
private String[] color1DArray = new String[]{
|
||||
"RED", "#FF0000",
|
||||
"GREEN", "#00FF00",
|
||||
"BLUE", "#0000FF"
|
||||
};
|
||||
private String[][] color2DArray = new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } };
|
||||
private String[] color1DArray = new String[] { "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" };
|
||||
private Map<String, String> colorMap;
|
||||
|
||||
@Before
|
||||
@@ -92,34 +84,26 @@ public class MapUtilsTest {
|
||||
Map<String, String> invColorMap = MapUtils.invertMap(this.colorMap);
|
||||
|
||||
int size = invColorMap.size();
|
||||
Assertions.assertThat(invColorMap)
|
||||
.hasSameSizeAs(colorMap)
|
||||
.containsKeys(this.colorMap.values().toArray(new String[size]))
|
||||
.containsValues(this.colorMap.keySet().toArray(new String[size]));
|
||||
Assertions.assertThat(invColorMap).hasSameSizeAs(colorMap).containsKeys(this.colorMap.values().toArray(new String[size])).containsValues(this.colorMap.keySet().toArray(new String[size]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateFixedSizedMapAndAdd_thenMustThrowException() {
|
||||
Map<String, String> rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll(
|
||||
new HashMap<String, String>(),
|
||||
this.color1DArray));
|
||||
Map<String, String> rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll(new HashMap<String, String>(), this.color1DArray));
|
||||
|
||||
rgbMap.put("ORANGE", "#FFA500");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddDuplicateToUniqueValuesPredicateMap_thenMustThrowException() {
|
||||
Map<String, String> uniqValuesMap
|
||||
= MapUtils.predicatedMap(this.colorMap, null, PredicateUtils.uniquePredicate());
|
||||
Map<String, String> uniqValuesMap = MapUtils.predicatedMap(this.colorMap, null, PredicateUtils.uniquePredicate());
|
||||
|
||||
uniqValuesMap.put("NEW_RED", "#FF0000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateLazyMap_theMapIsCreated() {
|
||||
Map<Integer, String> intStrMap = MapUtils.lazyMap(
|
||||
new HashMap<Integer, String>(),
|
||||
TransformerUtils.stringValueTransformer());
|
||||
Map<Integer, String> intStrMap = MapUtils.lazyMap(new HashMap<Integer, String>(), TransformerUtils.stringValueTransformer());
|
||||
|
||||
assertThat(intStrMap, is(anEmptyMap()));
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ public class SetUtilsUnitTest {
|
||||
public void givenSetAndPredicate_whenPredicatedSet_thenValidateSet_and_throw_IllegalArgumentException() {
|
||||
Set<String> sourceSet = new HashSet<>();
|
||||
sourceSet.addAll(Arrays.asList("London", "Lagos", "Err Source1"));
|
||||
Set<String> validatingSet
|
||||
= SetUtils.predicatedSet(sourceSet, (s) -> s.startsWith("L"));
|
||||
Set<String> validatingSet = SetUtils.predicatedSet(sourceSet, (s) -> s.startsWith("L"));
|
||||
validatingSet.add("Err Source2");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OrderedMapUnitTest {
|
||||
|
||||
private String[] names = {"Emily", "Mathew", "Rose", "John", "Anna"};
|
||||
private Integer[] ages = {37, 28, 40, 36, 21};
|
||||
private String[] names = { "Emily", "Mathew", "Rose", "John", "Anna" };
|
||||
private Integer[] ages = { 37, 28, 40, 36, 21 };
|
||||
|
||||
private int RUNNERS_COUNT = names.length;
|
||||
|
||||
|
||||
@@ -15,94 +15,88 @@ import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class BagTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void givenMultipleCopies_whenAdded_theCountIsKept() {
|
||||
Bag<Integer> bag = new HashBag<>(
|
||||
Arrays.asList(new Integer[] { 1, 2, 3, 3, 3, 1, 4 }));
|
||||
|
||||
Bag<Integer> bag = new HashBag<>(Arrays.asList(new Integer[] { 1, 2, 3, 3, 3, 1, 4 }));
|
||||
|
||||
assertThat(bag.getCount(1), equalTo(2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenBag_whenBagAddAPILikeCollectionAPI_thenFalse() {
|
||||
Collection<Integer> collection = new ArrayList<>();
|
||||
|
||||
|
||||
// Collection contract defines that add() should return true
|
||||
assertThat(collection.add(9), is(true));
|
||||
|
||||
|
||||
// Even when element is already in the collection
|
||||
collection.add(1);
|
||||
assertThat(collection.add(1), is(true));
|
||||
|
||||
|
||||
Bag<Integer> bag = new HashBag<>();
|
||||
|
||||
|
||||
// Bag returns true on adding a new element
|
||||
assertThat(bag.add(9), is(true));
|
||||
|
||||
|
||||
bag.add(1);
|
||||
// But breaks the contract with false when it has to increment the count
|
||||
assertThat(bag.add(1), is(not(true)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenDecoratedBag_whenBagAddAPILikeCollectionAPI_thenTrue() {
|
||||
Bag<Integer> bag = CollectionBag.collectionBag(new HashBag<>());
|
||||
|
||||
|
||||
bag.add(1);
|
||||
// This time the behavior is compliant to the Java Collection
|
||||
assertThat(bag.add(1), is((true)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenAdd_whenCountOfElementsDefined_thenCountAreAdded() {
|
||||
Bag<Integer> bag = new HashBag<>();
|
||||
|
||||
|
||||
// Adding 1 for 5 times
|
||||
bag.add(1, 5);
|
||||
assertThat(bag.getCount(1), equalTo(5));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenMultipleCopies_whenRemove_allAreRemoved() {
|
||||
Bag<Integer> bag = new HashBag<>(
|
||||
Arrays.asList(new Integer[] { 1, 2, 3, 3, 3, 1, 4 }));
|
||||
|
||||
Bag<Integer> bag = new HashBag<>(Arrays.asList(new Integer[] { 1, 2, 3, 3, 3, 1, 4 }));
|
||||
|
||||
// From 3 we delete 1, 2 remain
|
||||
bag.remove(3, 1);
|
||||
assertThat(bag.getCount(3), equalTo(2));
|
||||
|
||||
|
||||
// From 2 we delete all
|
||||
bag.remove(1);
|
||||
assertThat(bag.getCount(1), equalTo(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTree_whenDuplicateElementsAdded_thenSort() {
|
||||
TreeBag<Integer> bag = new TreeBag<>(
|
||||
Arrays.asList(new Integer[] { 7, 5, 1, 7, 2, 3, 3, 3, 1, 4, 7 }));
|
||||
|
||||
TreeBag<Integer> bag = new TreeBag<>(Arrays.asList(new Integer[] { 7, 5, 1, 7, 2, 3, 3, 3, 1, 4, 7 }));
|
||||
|
||||
assertThat(bag.first(), equalTo(1));
|
||||
assertThat(bag.getCount(bag.first()), equalTo(2));
|
||||
assertThat(bag.last(), equalTo(7));
|
||||
assertThat(bag.getCount(bag.last()), equalTo(3));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenDecoratedTree_whenTreeAddAPILikeCollectionAPI_thenTrue() {
|
||||
SortedBag<Integer> bag = CollectionSortedBag
|
||||
.collectionSortedBag(new TreeBag<>());
|
||||
|
||||
SortedBag<Integer> bag = CollectionSortedBag.collectionSortedBag(new TreeBag<>());
|
||||
|
||||
bag.add(1);
|
||||
assertThat(bag.add(1), is((true)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenSortedBag_whenDuplicateElementsAdded_thenSort() {
|
||||
SynchronizedSortedBag<Integer> bag = SynchronizedSortedBag
|
||||
.synchronizedSortedBag(new TreeBag<>(
|
||||
Arrays.asList(new Integer[] { 7, 5, 1, 7, 2, 3, 3, 3, 1, 4, 7 })));
|
||||
|
||||
SynchronizedSortedBag<Integer> bag = SynchronizedSortedBag.synchronizedSortedBag(new TreeBag<>(Arrays.asList(new Integer[] { 7, 5, 1, 7, 2, 3, 3, 3, 1, 4, 7 })));
|
||||
|
||||
assertThat(bag.first(), equalTo(1));
|
||||
assertThat(bag.getCount(bag.first()), equalTo(2));
|
||||
assertThat(bag.last(), equalTo(7));
|
||||
|
||||
@@ -29,10 +29,7 @@ public class CSVReaderWriterTest {
|
||||
@Test
|
||||
public void givenCSVFile_whenRead_thenContentsAsExpected() throws IOException {
|
||||
Reader in = new FileReader("src/test/resources/book.csv");
|
||||
Iterable<CSVRecord> records = CSVFormat.DEFAULT
|
||||
.withHeader(HEADERS)
|
||||
.withFirstRecordAsHeader()
|
||||
.parse(in);
|
||||
Iterable<CSVRecord> records = CSVFormat.DEFAULT.withHeader(HEADERS).withFirstRecordAsHeader().parse(in);
|
||||
for (CSVRecord record : records) {
|
||||
String author = record.get("author");
|
||||
String title = record.get("title");
|
||||
@@ -52,9 +49,7 @@ public class CSVReaderWriterTest {
|
||||
}
|
||||
});
|
||||
}
|
||||
assertEquals(EXPECTED_FILESTREAM, sw
|
||||
.toString()
|
||||
.trim());
|
||||
assertEquals(EXPECTED_FILESTREAM, sw.toString().trim());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,10 +47,8 @@ public class DbUtilsUnitTest {
|
||||
List<Map<String, Object>> list = runner.query(connection, "SELECT * FROM employee", beanListHandler);
|
||||
|
||||
assertEquals(list.size(), 5);
|
||||
assertEquals(list.get(0)
|
||||
.get("firstname"), "John");
|
||||
assertEquals(list.get(4)
|
||||
.get("firstname"), "Christian");
|
||||
assertEquals(list.get(0).get("firstname"), "John");
|
||||
assertEquals(list.get(4).get("firstname"), "Christian");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,10 +59,8 @@ public class DbUtilsUnitTest {
|
||||
List<Employee> employeeList = runner.query(connection, "SELECT * FROM employee", beanListHandler);
|
||||
|
||||
assertEquals(employeeList.size(), 5);
|
||||
assertEquals(employeeList.get(0)
|
||||
.getFirstName(), "John");
|
||||
assertEquals(employeeList.get(4)
|
||||
.getFirstName(), "Christian");
|
||||
assertEquals(employeeList.get(0).getFirstName(), "John");
|
||||
assertEquals(employeeList.get(4).getFirstName(), "Christian");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,12 +81,8 @@ public class DbUtilsUnitTest {
|
||||
QueryRunner runner = new QueryRunner();
|
||||
List<Employee> employees = runner.query(connection, "SELECT * FROM employee", employeeHandler);
|
||||
|
||||
assertEquals(employees.get(0)
|
||||
.getEmails()
|
||||
.size(), 2);
|
||||
assertEquals(employees.get(2)
|
||||
.getEmails()
|
||||
.size(), 3);
|
||||
assertEquals(employees.get(0).getEmails().size(), 2);
|
||||
assertEquals(employees.get(2).getEmails().size(), 3);
|
||||
assertNotNull(employees.get(0).getEmails().get(0).getEmployeeId());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,30 +25,23 @@ import java.nio.charset.Charset;
|
||||
public class CommonsIOUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCopyANDReadFileTesttxt_thenMatchExpectedData()
|
||||
throws IOException {
|
||||
public void whenCopyANDReadFileTesttxt_thenMatchExpectedData() throws IOException {
|
||||
|
||||
String expectedData = "Hello World from fileTest.txt!!!";
|
||||
|
||||
File file = FileUtils.getFile(getClass().getClassLoader()
|
||||
.getResource("fileTest.txt")
|
||||
.getPath());
|
||||
File file = FileUtils.getFile(getClass().getClassLoader().getResource("fileTest.txt").getPath());
|
||||
File tempDir = FileUtils.getTempDirectory();
|
||||
FileUtils.copyFileToDirectory(file, tempDir);
|
||||
File newTempFile = FileUtils.getFile(tempDir, file.getName());
|
||||
String data = FileUtils.readFileToString(newTempFile,
|
||||
Charset.defaultCharset());
|
||||
String data = FileUtils.readFileToString(newTempFile, Charset.defaultCharset());
|
||||
|
||||
Assert.assertEquals(expectedData, data.trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFileNameUtils_thenshowdifferentFileOperations()
|
||||
throws IOException {
|
||||
public void whenUsingFileNameUtils_thenshowdifferentFileOperations() throws IOException {
|
||||
|
||||
String path = getClass().getClassLoader()
|
||||
.getResource("fileTest.txt")
|
||||
.getPath();
|
||||
String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
|
||||
|
||||
String fullPath = FilenameUtils.getFullPath(path);
|
||||
String extension = FilenameUtils.getExtension(path);
|
||||
@@ -60,70 +53,54 @@ public class CommonsIOUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingFileSystemUtils_thenDriveFreeSpace()
|
||||
throws IOException {
|
||||
public void whenUsingFileSystemUtils_thenDriveFreeSpace() throws IOException {
|
||||
|
||||
long freeSpace = FileSystemUtils.freeSpaceKb("/");
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
public void whenUsingTeeInputOutputStream_thenWriteto2OutputStreams()
|
||||
throws IOException {
|
||||
public void whenUsingTeeInputOutputStream_thenWriteto2OutputStreams() throws IOException {
|
||||
|
||||
final String str = "Hello World.";
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes());
|
||||
ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
|
||||
|
||||
FilterOutputStream teeOutputStream = new TeeOutputStream(outputStream1,outputStream2);
|
||||
|
||||
FilterOutputStream teeOutputStream = new TeeOutputStream(outputStream1, outputStream2);
|
||||
new TeeInputStream(inputStream, teeOutputStream, true).read(new byte[str.length()]);
|
||||
|
||||
|
||||
Assert.assertEquals(str, String.valueOf(outputStream1));
|
||||
Assert.assertEquals(str, String.valueOf(outputStream2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetFilewithNameFileFilter_thenFindfileTesttxt()
|
||||
throws IOException {
|
||||
public void whenGetFilewithNameFileFilter_thenFindfileTesttxt() throws IOException {
|
||||
|
||||
final String testFile = "fileTest.txt";
|
||||
|
||||
String path = getClass().getClassLoader()
|
||||
.getResource(testFile)
|
||||
.getPath();
|
||||
String path = getClass().getClassLoader().getResource(testFile).getPath();
|
||||
File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));
|
||||
|
||||
String[] possibleNames = { "NotThisOne", testFile };
|
||||
|
||||
Assert.assertEquals(testFile,
|
||||
dir.list(new NameFileFilter(possibleNames, IOCase.INSENSITIVE))[0]);
|
||||
Assert.assertEquals(testFile, dir.list(new NameFileFilter(possibleNames, IOCase.INSENSITIVE))[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt()
|
||||
throws IOException {
|
||||
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt() throws IOException {
|
||||
|
||||
String path = getClass().getClassLoader()
|
||||
.getResource("fileTest.txt")
|
||||
.getPath();
|
||||
String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
|
||||
File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));
|
||||
|
||||
Assert.assertEquals("sample.txt",
|
||||
dir.list(new AndFileFilter(
|
||||
new WildcardFileFilter("*ple*", IOCase.INSENSITIVE),
|
||||
new SuffixFileFilter("txt")))[0]);
|
||||
Assert.assertEquals("sample.txt", dir.list(new AndFileFilter(new WildcardFileFilter("*ple*", IOCase.INSENSITIVE), new SuffixFileFilter("txt")))[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSortDirWithPathFileComparator_thenFirstFileaaatxt()
|
||||
throws IOException {
|
||||
public void whenSortDirWithPathFileComparator_thenFirstFileaaatxt() throws IOException {
|
||||
|
||||
PathFileComparator pathFileComparator = new PathFileComparator(
|
||||
IOCase.INSENSITIVE);
|
||||
String path = FilenameUtils.getFullPath(getClass().getClassLoader()
|
||||
.getResource("fileTest.txt")
|
||||
.getPath());
|
||||
PathFileComparator pathFileComparator = new PathFileComparator(IOCase.INSENSITIVE);
|
||||
String path = FilenameUtils.getFullPath(getClass().getClassLoader().getResource("fileTest.txt").getPath());
|
||||
File dir = new File(path);
|
||||
File[] files = dir.listFiles();
|
||||
|
||||
@@ -133,16 +110,11 @@ public class CommonsIOUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSizeFileComparator_thenLargerFile()
|
||||
throws IOException {
|
||||
public void whenSizeFileComparator_thenLargerFile() throws IOException {
|
||||
|
||||
SizeFileComparator sizeFileComparator = new SizeFileComparator();
|
||||
File largerFile = FileUtils.getFile(getClass().getClassLoader()
|
||||
.getResource("fileTest.txt")
|
||||
.getPath());
|
||||
File smallerFile = FileUtils.getFile(getClass().getClassLoader()
|
||||
.getResource("sample.txt")
|
||||
.getPath());
|
||||
File largerFile = FileUtils.getFile(getClass().getClassLoader().getResource("fileTest.txt").getPath());
|
||||
File smallerFile = FileUtils.getFile(getClass().getClassLoader().getResource("sample.txt").getPath());
|
||||
|
||||
int i = sizeFileComparator.compare(largerFile, smallerFile);
|
||||
|
||||
|
||||
@@ -9,71 +9,71 @@ import static org.junit.Assert.assertEquals;
|
||||
public class ArrayUtilsUnitTest {
|
||||
@Test
|
||||
public void givenArray_whenAddingElementAtSpecifiedPosition_thenCorrect() {
|
||||
int[] oldArray = {2, 3, 4, 5};
|
||||
int[] oldArray = { 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.add(oldArray, 0, 1);
|
||||
int[] expectedArray = {1, 2, 3, 4, 5};
|
||||
int[] expectedArray = { 1, 2, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenAddingElementAtTheEnd_thenCorrect() {
|
||||
int[] oldArray = {2, 3, 4, 5};
|
||||
int[] oldArray = { 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.add(oldArray, 1);
|
||||
int[] expectedArray = {2, 3, 4, 5, 1};
|
||||
int[] expectedArray = { 2, 3, 4, 5, 1 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenAddingAllElementsAtTheEnd_thenCorrect() {
|
||||
int[] oldArray = {0, 1, 2};
|
||||
int[] oldArray = { 0, 1, 2 };
|
||||
int[] newArray = ArrayUtils.addAll(oldArray, 3, 4, 5);
|
||||
int[] expectedArray = {0, 1, 2, 3, 4, 5};
|
||||
int[] expectedArray = { 0, 1, 2, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingElementAtSpecifiedPosition_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 3, 4, 5};
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.remove(oldArray, 1);
|
||||
int[] expectedArray = {1, 3, 4, 5};
|
||||
int[] expectedArray = { 1, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAllElementsAtSpecifiedPositions_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 3, 4, 5};
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.removeAll(oldArray, 1, 3);
|
||||
int[] expectedArray = {1, 3, 5};
|
||||
int[] expectedArray = { 1, 3, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAnElement_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 3, 3, 4};
|
||||
int[] oldArray = { 1, 2, 3, 3, 4 };
|
||||
int[] newArray = ArrayUtils.removeElement(oldArray, 3);
|
||||
int[] expectedArray = {1, 2, 3, 4};
|
||||
int[] expectedArray = { 1, 2, 3, 4 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingElements_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 3, 3, 4};
|
||||
int[] oldArray = { 1, 2, 3, 3, 4 };
|
||||
int[] newArray = ArrayUtils.removeElements(oldArray, 2, 3, 5);
|
||||
int[] expectedArray = {1, 3, 4};
|
||||
int[] expectedArray = { 1, 3, 4 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAllElementOccurences_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 2, 2, 3};
|
||||
int[] oldArray = { 1, 2, 2, 2, 3 };
|
||||
int[] newArray = ArrayUtils.removeAllOccurences(oldArray, 2);
|
||||
int[] expectedArray = {1, 3};
|
||||
int[] expectedArray = { 1, 3 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenCheckingExistingElement_thenCorrect() {
|
||||
int[] array = {1, 3, 5, 7, 9};
|
||||
int[] array = { 1, 3, 5, 7, 9 };
|
||||
boolean evenContained = ArrayUtils.contains(array, 2);
|
||||
boolean oddContained = ArrayUtils.contains(array, 7);
|
||||
assertEquals(false, evenContained);
|
||||
@@ -82,57 +82,57 @@ public class ArrayUtilsUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenArray_whenReversingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.reverse(originalArray, 1, 4);
|
||||
int[] expectedArray = {1, 4, 3, 2, 5};
|
||||
int[] expectedArray = { 1, 4, 3, 2, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenReversingAllElements_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.reverse(originalArray);
|
||||
int[] expectedArray = {5, 4, 3, 2, 1};
|
||||
int[] expectedArray = { 5, 4, 3, 2, 1 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenShiftingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.shift(originalArray, 1, 4, 1);
|
||||
int[] expectedArray = {1, 4, 2, 3, 5};
|
||||
int[] expectedArray = { 1, 4, 2, 3, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenShiftingAllElements_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.shift(originalArray, 1);
|
||||
int[] expectedArray = {5, 1, 2, 3, 4};
|
||||
int[] expectedArray = { 5, 1, 2, 3, 4 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenExtractingElements_thenCorrect() {
|
||||
int[] oldArray = {1, 2, 3, 4, 5};
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.subarray(oldArray, 2, 7);
|
||||
int[] expectedArray = {3, 4, 5};
|
||||
int[] expectedArray = { 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenSwapingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.swap(originalArray, 0, 3, 2);
|
||||
int[] expectedArray = {4, 5, 3, 1, 2};
|
||||
int[] expectedArray = { 4, 5, 3, 1, 2 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenSwapingElementsAtSpecifiedPositions_thenCorrect() {
|
||||
int[] originalArray = {1, 2, 3, 4, 5};
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.swap(originalArray, 0, 3);
|
||||
int[] expectedArray = {4, 2, 3, 1, 5};
|
||||
int[] expectedArray = { 4, 2, 3, 1, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class IntegrationTest {
|
||||
|
||||
final double i = integrator.integrate(100, function, 0, 10);
|
||||
|
||||
Assert.assertEquals(16 + 2d/3d, i, 1e-7);
|
||||
Assert.assertEquals(16 + 2d / 3d, i, 1e-7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ public class LinearAlgebraUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenDecompositionSolverSolve_thenCorrect() {
|
||||
RealMatrix a =
|
||||
new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } },
|
||||
false);
|
||||
RealMatrix a = new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } }, false);
|
||||
RealVector b = new ArrayRealVector(new double[] { 1, -2, 1 }, false);
|
||||
|
||||
DecompositionSolver solver = new LUDecomposition(a).getSolver();
|
||||
|
||||
@@ -12,10 +12,10 @@ public class StatisticsUnitTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
values = new double[] {65, 51 , 16, 11 , 6519, 191 ,0 , 98, 19854, 1, 32};
|
||||
values = new double[] { 65, 51, 16, 11, 6519, 191, 0, 98, 19854, 1, 32 };
|
||||
|
||||
descriptiveStatistics = new DescriptiveStatistics();
|
||||
for(double v : values) {
|
||||
for (double v : values) {
|
||||
descriptiveStatistics.addValue(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user