Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98c3f93

Browse files
committed
Review changes in Test Cases
1 parent26fbbed commit98c3f93

File tree

2 files changed

+63
-4
lines changed
  • collection-pipeline/src
    • main/java/com/iluwatar/collectionpipeline
    • test/java/com/iluwatar/collectionpipeline

2 files changed

+63
-4
lines changed

‎collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,52 @@ public Car(String make, String model, int yearOfMake, Category category) {
4545
this.category =category;
4646
}
4747

48+
@Override
49+
publicinthashCode() {
50+
finalintprime =31;
51+
intresult =1;
52+
result =prime *result + ((category ==null) ?0 :category.hashCode());
53+
result =prime *result + ((make ==null) ?0 :make.hashCode());
54+
result =prime *result + ((model ==null) ?0 :model.hashCode());
55+
result =prime *result +year;
56+
returnresult;
57+
}
58+
59+
@Override
60+
publicbooleanequals(Objectobj) {
61+
if (this ==obj) {
62+
returntrue;
63+
}
64+
if (obj ==null) {
65+
returnfalse;
66+
}
67+
if (getClass() !=obj.getClass()) {
68+
returnfalse;
69+
}
70+
Carother = (Car)obj;
71+
if (category !=other.category) {
72+
returnfalse;
73+
}
74+
if (make ==null) {
75+
if (other.make !=null) {
76+
returnfalse;
77+
}
78+
}elseif (!make.equals(other.make)) {
79+
returnfalse;
80+
}
81+
if (model ==null) {
82+
if (other.model !=null) {
83+
returnfalse;
84+
}
85+
}elseif (!model.equals(other.model)) {
86+
returnfalse;
87+
}
88+
if (year !=other.year) {
89+
returnfalse;
90+
}
91+
returntrue;
92+
}
93+
4894
publicStringgetMake() {
4995
returnmake;
5096
}

‎collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
2626

2727
importjava.util.Arrays;
28+
importjava.util.HashMap;
2829
importjava.util.List;
2930
importjava.util.Map;
3031

@@ -40,27 +41,39 @@ public class AppTest {
4041
@Test
4142
publicvoidtestGetModelsAfter2000UsingFor() {
4243
List<String>models =ImperativeProgramming.getModelsAfter2000(cars);
43-
assertEquals(models,Arrays.asList("Avenger","Wrangler","Focus","Cascada"));
44+
assertEquals(Arrays.asList("Avenger","Wrangler","Focus","Cascada"),models);
4445
}
4546

4647
@Test
4748
publicvoidtestGetModelsAfter2000UsingPipeline() {
4849
List<String>models =FunctionalProgramming.getModelsAfter2000(cars);
49-
assertEquals(models,Arrays.asList("Avenger","Wrangler","Focus","Cascada"));
50+
assertEquals(Arrays.asList("Avenger","Wrangler","Focus","Cascada"),models);
5051
}
5152

5253
@Test
5354
publicvoidtestGetGroupingOfCarsByCategory() {
55+
Map<Category,List<Car>>modelsExpected =newHashMap<>();
56+
modelsExpected.put(Category.CONVERTIBLE,Arrays.asList(newCar("Buick","Cascada",2016,Category.CONVERTIBLE),
57+
newCar("Chevrolet","Geo Metro",1992,Category.CONVERTIBLE)));
58+
modelsExpected.put(Category.SEDAN,Arrays.asList(newCar("Dodge","Avenger",2010,Category.SEDAN),
59+
newCar("Ford","Focus",2012,Category.SEDAN)));
60+
modelsExpected.put(Category.JEEP,Arrays.asList(newCar("Jeep","Wrangler",2011,Category.JEEP),
61+
newCar("Jeep","Comanche",1990,Category.JEEP)));
5462
Map<Category,List<Car>>modelsFunctional =FunctionalProgramming.getGroupingOfCarsByCategory(cars);
5563
Map<Category,List<Car>>modelsImperative =ImperativeProgramming.getGroupingOfCarsByCategory(cars);
56-
assertEquals(modelsFunctional,modelsImperative);
64+
System.out.println("Category " +modelsFunctional);
65+
assertEquals(modelsExpected,modelsFunctional);
66+
assertEquals(modelsExpected,modelsImperative);
5767
}
5868

5969
@Test
6070
publicvoidtestGetSedanCarsOwnedSortedByDate() {
6171
Personjohn =newPerson(cars);
72+
List<Car>modelsExpected =Arrays.asList(newCar("Dodge","Avenger",2010,Category.SEDAN),
73+
newCar("Ford","Focus",2012,Category.SEDAN));
6274
List<Car>modelsFunctional =FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
6375
List<Car>modelsImperative =ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
64-
assertEquals(modelsFunctional,modelsImperative);
76+
assertEquals(modelsExpected,modelsFunctional);
77+
assertEquals(modelsExpected,modelsImperative);
6578
}
6679
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp