Skip to content

Conversation

@dkaznacheev
Copy link
Owner

No description provided.

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Папка .gradle не нужна, .idea/workspace.xml тоже не нужен

* Binary search tree working as a set, capable of adding/checking elements.
* @param <T> type of the object it stores
*/
public class BinaryTree<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Класс без пакета

/**
* The binary tree subclass representing the node of a tree.
*/
class Node {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А точно нужна пакетная видимость?

class Node {
T value;
Node left;
Node right;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пакетная видимость у поля уж точно не нужна, если не хоитте, чтобы баллы за задачу ушли в минус :)

BinaryTree<Integer> binaryTree = new BinaryTree<>();
binaryTree.add(0);
binaryTree.add(10);
assert (binaryTree.size() == 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEquals, assert --- это не для тестов, а для проверки инвариантов во время выполнения


public class BinaryTreeTest {
@Test
public void add() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужны более адекватные имена тестов

for (Maybe<Integer> maybeInt : maybeArray) {
String toWrite;
try {
Integer result = maybeInt.map(value -> value*value).get();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Бинарные арифметические операции выделяются пробелами всегда

try {
Integer result = maybeInt.map(value -> value*value).get();
toWrite = Integer.toString(result);
} catch (NothingException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Плохая идея управлять исполнением программы с помощью исключений, исключения должны бросаться только в неожиданных ситуациях, а тут мы по условию знаем, что часть Maybe будет Maybe.nothing()

@@ -0,0 +1,2 @@
public class NothingException extends Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исключению тоже нужен комментарий

} catch (NothingException ex) {
exceptionThrown = true;
}
assert (exceptionThrown);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ужасно :) Для этого ведь есть параметр expected у @Test


public class MaybeTest {
@Test
public void get() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужны более содержателдьные комментарии к тестам

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Дерево зачтено, Maybe надо доправить

* @param value object to add
* @return true if there was this object already, false otherwise
*/
public boolean add (T value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пробел перед "(" лишний, тут и ниже

@@ -0,0 +1,76 @@
package ru.spbau.maybe;

import com.sun.istack.internal.NotNull;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я думаю, имелась в виду org.jetbrains.annotations.NotNull, а то в Java 9 такого нет

}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если хотите @NotNull, то надо зависимость от org.jetbrains.annotations тоже добавить

*/
private T value;

private Maybe (T t) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишний пробел

* @return Maybe containing null
*/
public static <T> Maybe<T> nothing() {
return nothing;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Имеет смысл добавить методу @SuppressWarnings("unchecked"), это же сырое значение

assert (mbString2.get().equals("test"));
} catch (NothingException ex) {
assert (false);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот ещё недобитые юнит-тесты :)

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Теперь всё ок, зачтена

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants