-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/test/java/tree/TreeTest.java
Outdated
|
|
||
|
|
||
| List<User> nodes = tree.getElements(); | ||
| for (int i = 0; i < arr.length; i++) { |
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.
You didn't tested that the order is actually correct.
Should be something like these:
assertEquals(Arrays.asList(andrii, rostik, //place all in correct order), nodes)
in order to test that order is correct.
|
Added fix to tree test and added words counter with tests. |
src/main/java/products/Category.java
Outdated
|
|
||
| public class Category { | ||
| private Categories category; | ||
| private List<Product> products = new ArrayList<>(); |
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.
can be final
src/main/java/products/Category.java
Outdated
| import java.util.List; | ||
|
|
||
| public class Category { | ||
| private Categories category; |
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.
Can be final.
| return category; | ||
| } | ||
|
|
||
| public List<Product> getProducts() { |
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.
You should not return list outside the class it make encapsulation weaker and sometimes causes bugs that are hard to investigate if some class outside adds something to the list.
Rather make copy of the list before returning it new ArrayList(products) or return immutable view of the list Collection.unidentifiableList(products)
src/main/java/products/Product.java
Outdated
|
|
||
| public class Product { | ||
|
|
||
| private List<Category> categoryList; |
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.
can be final
| private int count; | ||
| private int prise; | ||
|
|
||
| public List<Category> getCategories() { |
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.
see above comment about returning list directly.
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.
Making list final solves the problem of returning it directly. Okay
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.
No, it will not.
final List<Category> categoryList = new ArrayList<>();
final doesn't allow to reassign link categoryList but it allows to add elements to list. e.g.
So caller of your method can do the following, that may cause bugs.
List<Category> categoryList product.getCategories()
categotyList.clear()
So I recommend to return copies or immutable copies.
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.
Got it. Thank you!
src/main/java/words/Counter.java
Outdated
|
|
||
| private String[] convertToArray(String string){ | ||
| string = string.trim(); | ||
| String[] wordArray = string.split(" "); |
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.
you can inline simple exptestions:
return string.trim().splt(" ")
string is terrible name) use input or something like that.
src/main/java/words/Counter.java
Outdated
| return false; | ||
| } else { | ||
| for (String word : convertToArray(string)) { | ||
| if (words.containsKey(word)) { |
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.
can be simplified:
int count = words.getOrDefault(word, 0)
words.put(word, count + 1)
src/main/java/words/Counter.java
Outdated
| } | ||
|
|
||
| public Map<String, Integer> getFrequency(){ | ||
| return words; |
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.
do not return Map directly make a copy new HashMap(words) or Collections.unmodifiableMap(words)
src/main/java/products/Stock.java
Outdated
| return categoriesOfProduct; | ||
| } | ||
|
|
||
| public void addProduct (Categories[] category, String name, int count, int price){ |
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.
You can improve your method signature match by using varargs: https://www.geeksforgeeks.org/variable-arguments-varargs-in-java/
public void addProduct (String name, int count, int price, Categories... category)
so you can call it in the following way:
addProduct("sdf", 5, Categories.Sweet,Categories.Chocolate)
| } | ||
|
|
||
| @Test | ||
| public void frequency(){ |
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.
I will recommend to simplify test.
You can call several times count
e.g. count('Hello world"), count("Hello Vetal"), count("a")
Map<String, Integer> expected = new HashMap<>()
expected.put("hello", 2)
expected.put("world", 1)
...
assertEquals(expected, counter.getFrequency)
…tion parser and single test for it.
…ating random location's data.
…d for ClusterManager and boolean inBounds method for LatLng type.
Created tree tests.