Skip to content

Commit

Permalink
Merge pull request #53 from AY2223S1-CS2103T-W11-4/master
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
ciaoosuuu authored Oct 17, 2022
2 parents b4d2cab + cb0b828 commit f62dbff
Show file tree
Hide file tree
Showing 75 changed files with 4,704 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/waddle/model/itinerary/People.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class People {

public static final String MESSAGE_CONSTRAINTS =
"Number of people should only contain numbers";
public static final String VALIDATION_REGEX = "\\d";
public static final String VALIDATION_REGEX = "\\d+";

public final String numOfPeople;

Expand Down
3 changes: 3 additions & 0 deletions src/test/data/ConfigUtilTest/EmptyConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
5 changes: 5 additions & 0 deletions src/test/data/ConfigUtilTest/ExtraValuesConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"logLevel" : "INFO",
"userPrefsFilePath" : "preferences.json",
"extra" : "extra value"
}
1 change: 1 addition & 0 deletions src/test/data/ConfigUtilTest/NotJsonFormatConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this file is not in json format!
4 changes: 4 additions & 0 deletions src/test/data/ConfigUtilTest/TypicalConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"logLevel" : "INFO",
"userPrefsFilePath" : "preferences.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"itineraries" : [ {
"name" : "Spring Trip",
"country" : "Australia",
"startDate" : "2022-01-01",
"endDate" : "2022-01-15",
"people" : "1",
"items" : [ ]
}, {
"name" : "Spring Trip",
"country" : "Australia",
"startDate" : "2022-01-01",
"endDate" : "2022-01-15",
"people" : "1",
"items" : [ ]
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"itineraries" : [ {
"name" : "Spring Trip",
"country" : "Australia",
"startDate" : "10",
"endDate" : "20",
"people" : "1",
"items" : [ ]
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"_comment": "Waddle save file which contains the same Itinerary values as in TypicalItineraries#getTypicalWaddle()",
"itineraries" : [ {
"name" : "Spring Trip",
"country" : "Australia",
"startDate" : "2022-01-01",
"endDate" : "2022-01-15",
"people" : "1",
"items" : [ ]
}, {
"name" : "Autumn Hiking",
"country" : "Canada",
"startDate" : "2022-02-02",
"endDate" : "2022-02-23",
"people" : "2",
"items" : [ ]
}, {
"name" : "Graduation Trip",
"country" : "France",
"startDate" : "2022-03-03",
"endDate" : "2022-03-07",
"people" : "4",
"items" : [ ]
} ]
}
3 changes: 3 additions & 0 deletions src/test/data/JsonUserPrefsStorageTest/EmptyUserPrefs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
13 changes: 13 additions & 0 deletions src/test/data/JsonUserPrefsStorageTest/ExtraValuesUserPref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"guiSettings" : {
"windowWidth" : 1000.0,
"windowHeight" : 500.0,
"extra" : "some value ",
"windowCoordinates" : {
"x" : 300,
"y" : 100,
"z" : 99
}
},
"addressBookFilePath" : "addressbook.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Not a json file!
11 changes: 11 additions & 0 deletions src/test/data/JsonUserPrefsStorageTest/TypicalUserPref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"guiSettings" : {
"windowWidth" : 1000.0,
"windowHeight" : 500.0,
"windowCoordinates" : {
"x" : 300,
"y" : 100
}
},
"addressBookFilePath" : "waddle.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"persons": [ {
"name": "Valid Person",
"phone": "9482424",
"email": "[email protected]",
"address": "4th street"
}, {
"name": "Person With Invalid Phone Field",
"phone": "948asdf2424",
"email": "[email protected]",
"address": "4th street"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"persons": [ {
"name": "Person with invalid name field: Ha!ns Mu@ster",
"phone": "9482424",
"email": "[email protected]",
"address": "4th street"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not json format!
58 changes: 58 additions & 0 deletions src/test/java/seedu/waddle/AppParametersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seedu.waddle;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import javafx.application.Application;

public class AppParametersTest {

private final ParametersStub parametersStub = new ParametersStub();
private final AppParameters expected = new AppParameters();

@Test
public void parse_validConfigPath_success() {
parametersStub.namedParameters.put("config", "config.json");
expected.setConfigPath(Paths.get("config.json"));
assertEquals(expected, AppParameters.parse(parametersStub));
}

@Test
public void parse_nullConfigPath_success() {
parametersStub.namedParameters.put("config", null);
assertEquals(expected, AppParameters.parse(parametersStub));
}

@Test
public void parse_invalidConfigPath_success() {
parametersStub.namedParameters.put("config", "a\0");
expected.setConfigPath(null);
assertEquals(expected, AppParameters.parse(parametersStub));
}

private static class ParametersStub extends Application.Parameters {
private Map<String, String> namedParameters = new HashMap<>();

@Override
public List<String> getRaw() {
throw new AssertionError("should not be called");
}

@Override
public List<String> getUnnamed() {
throw new AssertionError("should not be called");
}

@Override
public Map<String, String> getNamed() {
return Collections.unmodifiableMap(namedParameters);
}
}
}
27 changes: 27 additions & 0 deletions src/test/java/seedu/waddle/commons/core/ConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.waddle.commons.core;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class ConfigTest {

@Test
public void toString_defaultObject_stringReturned() {
String defaultConfigAsString = "Current log level : INFO\n"
+ "Preference file Location : preferences.json";

assertEquals(defaultConfigAsString, new Config().toString());
}

@Test
public void equalsMethod() {
Config defaultConfig = new Config();
assertNotNull(defaultConfig);
assertTrue(defaultConfig.equals(defaultConfig));
}


}
135 changes: 135 additions & 0 deletions src/test/java/seedu/waddle/commons/core/VersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package seedu.waddle.commons.core;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.waddle.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

public class VersionTest {

@Test
public void versionParsing_acceptableVersionString_parsedVersionCorrectly() {
verifyVersionParsedCorrectly("V0.0.0ea", 0, 0, 0, true);
verifyVersionParsedCorrectly("V3.10.2", 3, 10, 2, false);
verifyVersionParsedCorrectly("V100.100.100ea", 100, 100, 100, true);
}

@Test
public void versionParsing_wrongVersionString_throwIllegalArgumentException() {
assertThrows(IllegalArgumentException.class, () -> Version.fromString("This is not a version string"));
}

@Test
public void versionConstructor_correctParameter_valueAsExpected() {
Version version = new Version(19, 10, 20, true);

assertEquals(19, version.getMajor());
assertEquals(10, version.getMinor());
assertEquals(20, version.getPatch());
assertEquals(true, version.isEarlyAccess());
}

@Test
public void versionToString_validVersion_correctStringRepresentation() {
// boundary at 0
Version version = new Version(0, 0, 0, true);
assertEquals("V0.0.0ea", version.toString());

// normal values
version = new Version(4, 10, 5, false);
assertEquals("V4.10.5", version.toString());

// big numbers
version = new Version(100, 100, 100, true);
assertEquals("V100.100.100ea", version.toString());
}

@Test
public void versionComparable_validVersion_compareToIsCorrect() {
Version one;
Version another;

// Tests equality
one = new Version(0, 0, 0, true);
another = new Version(0, 0, 0, true);
assertTrue(one.compareTo(another) == 0);

one = new Version(11, 12, 13, false);
another = new Version(11, 12, 13, false);
assertTrue(one.compareTo(another) == 0);

// Tests different patch
one = new Version(0, 0, 5, false);
another = new Version(0, 0, 0, false);
assertTrue(one.compareTo(another) > 0);

// Tests different minor
one = new Version(0, 0, 0, false);
another = new Version(0, 5, 0, false);
assertTrue(one.compareTo(another) < 0);

// Tests different major
one = new Version(10, 0, 0, true);
another = new Version(0, 0, 0, true);
assertTrue(one.compareTo(another) > 0);

// Tests high major vs low minor
one = new Version(10, 0, 0, true);
another = new Version(0, 1, 0, true);
assertTrue(one.compareTo(another) > 0);

// Tests high patch vs low minor
one = new Version(0, 0, 10, false);
another = new Version(0, 1, 0, false);
assertTrue(one.compareTo(another) < 0);

// Tests same major minor different patch
one = new Version(2, 15, 0, false);
another = new Version(2, 15, 5, false);
assertTrue(one.compareTo(another) < 0);

// Tests early access vs not early access on same version number
one = new Version(2, 15, 0, true);
another = new Version(2, 15, 0, false);
assertTrue(one.compareTo(another) < 0);

// Tests early access lower version vs not early access higher version compare by version number first
one = new Version(2, 15, 0, true);
another = new Version(2, 15, 5, false);
assertTrue(one.compareTo(another) < 0);

// Tests early access higher version vs not early access lower version compare by version number first
one = new Version(2, 15, 0, false);
another = new Version(2, 15, 5, true);
assertTrue(one.compareTo(another) < 0);
}

@Test
public void versionComparable_validVersion_hashCodeIsCorrect() {
Version version = new Version(100, 100, 100, true);
assertEquals(100100100, version.hashCode());

version = new Version(10, 10, 10, false);
assertEquals(1010010010, version.hashCode());
}

@Test
public void versionComparable_validVersion_equalIsCorrect() {
Version one;
Version another;

one = new Version(0, 0, 0, false);
another = new Version(0, 0, 0, false);
assertTrue(one.equals(another));

one = new Version(100, 191, 275, true);
another = new Version(100, 191, 275, true);
assertTrue(one.equals(another));
}

private void verifyVersionParsedCorrectly(String versionString,
int major, int minor, int patch, boolean isEarlyAccess) {
assertEquals(new Version(major, minor, patch, isEarlyAccess), Version.fromString(versionString));
}
}
Loading

0 comments on commit f62dbff

Please sign in to comment.