Review changes in Test Cases
This commit is contained in:
parent
26fbbed62e
commit
98c3f93e82
@ -45,6 +45,52 @@ public class Car {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((category == null) ? 0 : category.hashCode());
|
||||
result = prime * result + ((make == null) ? 0 : make.hashCode());
|
||||
result = prime * result + ((model == null) ? 0 : model.hashCode());
|
||||
result = prime * result + year;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Car other = (Car) obj;
|
||||
if (category != other.category) {
|
||||
return false;
|
||||
}
|
||||
if (make == null) {
|
||||
if (other.make != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!make.equals(other.make)) {
|
||||
return false;
|
||||
}
|
||||
if (model == null) {
|
||||
if (other.model != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!model.equals(other.model)) {
|
||||
return false;
|
||||
}
|
||||
if (year != other.year) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getMake() {
|
||||
return make;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ package com.iluwatar.collectionpipeline;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -40,27 +41,39 @@ public class AppTest {
|
||||
@Test
|
||||
public void testGetModelsAfter2000UsingFor() {
|
||||
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
|
||||
assertEquals(models, Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"));
|
||||
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetModelsAfter2000UsingPipeline() {
|
||||
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
|
||||
assertEquals(models, Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"));
|
||||
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupingOfCarsByCategory() {
|
||||
Map<Category, List<Car>> modelsExpected = new HashMap<>();
|
||||
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
|
||||
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
|
||||
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
||||
new Car("Ford", "Focus", 2012, Category.SEDAN)));
|
||||
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
|
||||
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
|
||||
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
|
||||
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
|
||||
assertEquals(modelsFunctional, modelsImperative);
|
||||
System.out.println("Category " + modelsFunctional);
|
||||
assertEquals(modelsExpected, modelsFunctional);
|
||||
assertEquals(modelsExpected, modelsImperative);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSedanCarsOwnedSortedByDate() {
|
||||
Person john = new Person(cars);
|
||||
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
||||
new Car("Ford", "Focus", 2012, Category.SEDAN));
|
||||
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
|
||||
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
|
||||
assertEquals(modelsFunctional, modelsImperative);
|
||||
assertEquals(modelsExpected, modelsFunctional);
|
||||
assertEquals(modelsExpected, modelsImperative);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user