-
Notifications
You must be signed in to change notification settings - Fork 12
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
Hello world and bubbleSort #14
base: master
Are you sure you want to change the base?
Conversation
val data : Array <Int> = arrayOf(1,5,3,6,7,3,2,9) | ||
println(Arrays.toString(data)) | ||
Starter.bubbleSort(data) | ||
println(Arrays.toString(data)) |
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.
В тесте нет assert - это по факту и не тест
} | ||
} | ||
} | ||
} |
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.
Выравнивайте форматирование кода (есть автоформат в IDEA CTRL+ALT+L)
bubbleSort(data) | ||
println(Arrays.toString(data)) | ||
} | ||
fun bubbleSort(toSort: Array<Int>) { |
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.
Функция должна быть в отдельном файле
ahmetoff/02/build.gradle
Outdated
@@ -0,0 +1,16 @@ | |||
plugins { | |||
id 'org.jetbrains.kotlin.jvm' version '1.3.72' |
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.
Версии в dependencies и плагина должны совпадать
} | ||
|
||
inter @Test | ||
fun bubbleSortTest() { |
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.
Случайно полетело, исправил
@@ -0,0 +1,10 @@ | |||
package ru.bmstu.iu4 | |||
|
|||
typealias Matrix = MutableList<MutableList<Int>> |
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.
typealias должен быть в файле с функциями
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.
Исправил
@@ -0,0 +1,111 @@ | |||
package ru.bmstu.iu4 | |||
|
|||
fun Matrix.init() { |
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.
функция должна называться не init, а random, причем почему-то ограниченный до 10
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.
Исправил
if (this[rows - 1][cols - 1] != null) { | ||
for (i in 0 until rows) { | ||
for (j in 0 until cols) { | ||
print(this[i][j]) |
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.
для этого есть println
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.
Исправил
fun Matrix.print() { | ||
val rows = this.size | ||
val cols = this[0].size | ||
if (this[rows - 1][cols - 1] != 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.
зачем эта проверка?
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.
Зачем ее печатать если она пустая
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.
Тут судя по объявлению 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.
решил убрать проверку на нулл, она здесь по сути совсем не нужна, это принт функция
val cols2 = matrix2[0].size | ||
|
||
if (rows1 == rows2 && cols1 == cols2) { | ||
if (matrix1[rows1 - 1][cols1 - 1] != 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.
аналогично, зачем эта проверка?
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.
ну сложить поэлементно матрицы можно, только если количество строк и столбцов у них равно
val rows2 = matrix2.size | ||
val cols2 = matrix2[0].size | ||
|
||
if (rows1 == rows2 && cols1 == cols2) { |
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.
Исправлено
} | ||
} | ||
|
||
fun Matrix.subtr(matrix1: Matrix, matrix2: Matrix) { |
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.
см. summ
} | ||
} | ||
|
||
fun Matrix.dotMult(matrix1: Matrix, matrix2: Matrix) { |
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.
см. summ
println() | ||
|
||
val matrix3: Matrix = MutableList(rows1, { MutableList(cols1, { 0 }) }) | ||
matrix3.subtr(matrix1, matrix2) |
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.
все функции должны быть в infix нотации
matrix3 = matrix1 subtr matrix2
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.
Всмысле нужно эту функцию сделать не как расширение, а как отдельную функцию, которая будет возварщать значение?
Опять в корень закомитили .gitignore |
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.
Опять бинарные файлы закоммитили :(
|
||
import kotlin.test.Test | ||
|
||
fun countCache(json: Persons): Double { |
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.
Должно быть сделано с использованием функций работы с коллекциями filter, 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.
Зачем вы удалил чужие файлы? О_о
fun Matrix.print() { | ||
val rows = this.size | ||
val cols = this[0].size | ||
if (this[rows - 1][cols - 1] != 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.
Тут судя по объявлению null никогда не будет. Я вам говорил про нулабилити элементы объявлены как не нулабл. если хотите проверять на то что матрица пустая, проверяйте по размеру
} | ||
} | ||
else { | ||
throw IllegalArgumentException ("Неправильно заданы размеры матриц.") |
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.
Сообщения в исключения лучше писать на английском
val rows2 = matrix2.size | ||
val cols2 = matrix2[0].size | ||
|
||
if (cols1 == rows2) { |
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.
Можно обойстись без этой дикой вложенности, инвертировав условие if
val tmp: Matrix = MutableList(cols1, { MutableList(rows1, { 0 }) }) | ||
|
||
for (i in 0..tmp.size - 1) { | ||
for (j in 0..tmp[0].size - 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.
можно использовать until
Восстановил папки соучащихся
Удален дублирущий гитигнор файл
Разрешение конфликтов
Разрешение конфликтов
No description provided.