-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
is this done alrd? :P |
Yeah I will submit a review now :P |
v1@yamgent submitted v1 for review.
Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/1/head:BRANCHNAME where |
btw for these |
Yup, thanks for the reminder Eugene ^^ |
} | ||
|
||
/** | ||
* Creates the tag labels for {@code person} and attach them to this {@code PersonCard}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether it's necessary to have and attach them to this {@code PersonCard}
since you have already mentioned the word tag labels
, so it sounds reasonable that it's gonna be on this PersonCard
@@ -36,6 +38,9 @@ public static void assertCardDisplaysPerson(Person expectedPerson, PersonCardHan | |||
assertEquals(expectedPerson.getAddress().value, actualCard.getAddress()); | |||
assertEquals(expectedPerson.getTags().stream().map(tag -> tag.tagName).collect(Collectors.toList()), | |||
actualCard.getTags()); | |||
expectedPerson.getTags().stream().map(tag -> tag.tagName).forEach(tag -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mapping
is unnecessary if we store the result of .collect(Collectors.toList())
on line 39.
@@ -36,6 +38,9 @@ public static void assertCardDisplaysPerson(Person expectedPerson, PersonCardHan | |||
assertEquals(expectedPerson.getAddress().value, actualCard.getAddress()); | |||
assertEquals(expectedPerson.getTags().stream().map(tag -> tag.tagName).collect(Collectors.toList()), | |||
actualCard.getTags()); | |||
expectedPerson.getTags().stream().map(tag -> tag.tagName).forEach(tag -> | |||
assertEquals(Arrays.asList("label", PersonCard.getTagColorStyleFor(tag)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extract "label" as a constant (it's just a default style class for all Label
objects right?), otherwise it's unintuitive :P
.filter(label -> label.getText().equals(tag)) | ||
.map(Label::getStyleClass) | ||
.findFirst() | ||
.orElse(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should throw exception instead to make the test fail faster :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I throw here? We don't have a NoSuchTagException
class or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IllegalArgumentException
should do. See here.
efdbfe4
to
db24d16
Compare
v2@yamgent submitted v2 for review.
(📚 Archive) (📈 Interdiff between v1 and v2) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/2/head:BRANCHNAME where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
actualCard.getTags()); | ||
|
||
List<String> expectedTags = expectedPerson.getTags().stream().map(tag -> tag.tagName) | ||
.collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we can put a newline before .map(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic suggestions
* Returns the color style for {@code tagName}'s label. | ||
*/ | ||
public static String getTagColorStyleFor(String tagName) { | ||
return TAG_COLOR_STYLES[Math.abs(tagName.hashCode()) % TAG_COLOR_STYLES.length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give explanatory comments about this calculation?
assertEquals(expectedTags, actualCard.getTags()); | ||
expectedTags.forEach(tag -> | ||
assertEquals(Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)), | ||
actualCard.getTagStyleClasses(tag))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of head scratching needed to figure out what is being verified here. use explanatory variables or comments to make it clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, or perhaps we can extract lines 44-47 into a method assertTagsEqual
.
Also, we need to update assertCardEquals(PersonCardHandle, PersonCardHandle)
right?
Also, I realised that for the expected result Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag))
, perhaps we shouldn't call PersonCard#getTagColorStyleFor(Tag)
cos the actual tags are initialised using that method too. So it's like in some sense, "ownself test ownself".
/** | ||
* Returns the color style for {@code tagName}'s label. | ||
*/ | ||
public static String getTagColorStyleFor(String tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like this method is public static
because it's required by the tests? ><
assertEquals(expectedTags, actualCard.getTags()); | ||
expectedTags.forEach(tag -> | ||
assertEquals(Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)), | ||
actualCard.getTagStyleClasses(tag))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, or perhaps we can extract lines 44-47 into a method assertTagsEqual
.
Also, we need to update assertCardEquals(PersonCardHandle, PersonCardHandle)
right?
Also, I realised that for the expected result Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag))
, perhaps we shouldn't call PersonCard#getTagColorStyleFor(Tag)
cos the actual tags are initialised using that method too. So it's like in some sense, "ownself test ownself".
db24d16
to
3df17df
Compare
v3@yamgent submitted v3 for review.
(📚 Archive) (📈 Interdiff between v2 and v3) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/3/head:BRANCHNAME where |
/** | ||
* Returns the color style for {@code tagName}'s label. | ||
*/ | ||
private static String getTagColorStyleFor(String tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there isn't a need for static
here I think
/** | ||
* Returns the color style for {@code tagName}'s label. | ||
*/ | ||
private static String getTagColorStyleFor(String tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I'm not too sure about this way of testing though. If we only have a few set values for tagName
, then maybe we should hardcode:
if (tagName.equals("foo")) {
return "teal";
} else...
Not too sure about it too, I thought it looks kinda weird cos we are calling the exact same code as the main code base, maybe @damithc can comment on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yamgent what do you think of hardcoding the expected values here? As mentioned, it is a bit odd to use the same code to test the a piece of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can hardcore the expected values. They can seem pretty arbitrary though, but I can add a comment to explain how the values were derived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added.
/** | ||
* Returns the color style for {@code tagName}'s label. | ||
*/ | ||
private static String getTagColorStyleFor(String tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yamgent what do you think of hardcoding the expected values here? As mentioned, it is a bit odd to use the same code to test the a piece of code.
3df17df
to
a0f850b
Compare
167b3d0
to
f6542d9
Compare
f6542d9
to
259e21f
Compare
v6@yamgent submitted v6 for review.
(📚 Archive) (📈 Interdiff between v5 and v6) (📈 Range-Diff between v5 and v6) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/6/head:BRANCHNAME where |
Changelog:
|
return "grey"; | ||
|
||
default: | ||
fail(tagName + " does not have a color assigned."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, after #894, we don't use fail
anymore.
The tags are all displayed with the same color. It is hard to differentiate between tags visually across contacts. For example, it is hard to visually group all contacts tagged with "colleague". It is also hard to differentiate between those contacts that are tagged with "colleague", and those that are not tagged with "colleague". Let's add different colors to different tag labels. Tags of the same name will always receive the same color, while different tag names should receive different colors if possible. The hashcode of the tag string is used to determine the tag color. This will assign a reasonably random color to each tag, and will also ensure that the tag color remains the same when the user launches the application again in the future (assuming the application version remains the same). The idea of using hashcode is influenced by a developer's suggestion[1]. [1] nus-cs2103-AY1718S1/forum#199
259e21f
to
1ac2e7c
Compare
v7@yamgent submitted v7 for review.
(📚 Archive) (📈 Interdiff between v6 and v7) (📈 Range-Diff between v6 and v7) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/7/head:BRANCHNAME where |
Part of #784. Rebased, and changed the design of determining the colours of the tag.
Propsed commit message:
Note: For demo purpose, don't merge this to master!