-
Notifications
You must be signed in to change notification settings - Fork 1
Деркунский Виктор. HW 3 #8
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: HW1
Are you sure you want to change the base?
Conversation
ottergottaott
left a comment
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.
Пока 5 баллов
| @Override | ||
| public String run(List<String> args, String before) { | ||
| if (args.isEmpty()) { | ||
| System.setProperty("user.dir", System.getProperty("user.home")); |
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.
Очень зря так меняете текущую директорию, как минимум сложно написать тесты на такой cd
| void testCdCommands() { | ||
| Command cd = new Cd(); | ||
| ArrayList<String> lst = new ArrayList<>(); | ||
| String res = System.getProperty("user.dir"); | ||
| cd.run(lst, ""); | ||
| Assertions.assertEquals(System.getProperty("user.home"), System.getProperty("user.dir")); | ||
| lst.add("main"); | ||
| cd.run(lst, ""); | ||
| Assertions.assertEquals(System.getProperty("user.dir"), res + "\\" + "main"); | ||
| } |
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 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.
Пишите больше тестов
| } | ||
| public static Command getCommand(String commandName) { | ||
| if (commandName.equals("pwd")) { | ||
| return new Pwd(); |
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.
А что с форматированием стало? Почему 4 пробела вдруг на 2 заменились?
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.
в ксц на java другие требования, забываю в editor менять
| File curDir = new File("."); | ||
| for (File file : Objects.requireNonNull(curDir.listFiles())) { | ||
| String name = file.getName(); | ||
| if (!name.startsWith(".")) { |
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.
А почему тут только в одном месте пропускаете скрытые файлы, а ниже этого не делаете?
Вообще код здесь обобщается, мы же все равно в любом случае должны пройти директорию, даже если это просто ..
ottergottaott
left a comment
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.
8 баллов
| Command ls = new Ls(); | ||
| ArrayList<String> lst = new ArrayList<>(); | ||
| String expected = "build build.gradle.kts gradle gradlew gradlew.bat README.md settings.gradle src testFiles"; | ||
| String expected = ".git .github .gradle .idea build build.gradle.kts gradle gradlew gradlew.bat README.md settings.gradle src testFiles"; |
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.
Вообще такие тесты плохие, т.к. содержимое корневой директории очевидно еще будет меняться
| } else { | ||
| File file = new File(args.get(0)); | ||
| System.setProperty("user.dir", file.getAbsolutePath()); | ||
| var path = Paths.get(System.getProperty("user.dir"), args.get(1)); |
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.
Все равно лучше было сделать внутреннюю переменную для этого или прям переменной окружения
Очень приятная архитектура, чтобы расширять, требовалось только написать свою команду и добавить ей в списке comandbuilder. Интерфейс команды тоже понятный, аналогичный моему, да и впринципе при вынесении всех команд в свою директорию максимально логично. Хоть у меня было написано на питоне, а здесь все на java, тоже не составило проблем что-то писать. Единтсвенное у меня не запустились тесты, но я думаю это из-за того, что я на windows это делал. Свои тесты запускались и проходили.