Skip to content
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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

akhmetov-dev
Copy link

No description provided.

val data : Array <Int> = arrayOf(1,5,3,6,7,3,2,9)
println(Arrays.toString(data))
Starter.bubbleSort(data)
println(Arrays.toString(data))
Copy link
Owner

Choose a reason for hiding this comment

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

В тесте нет assert - это по факту и не тест

}
}
}
}
Copy link
Owner

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>) {
Copy link
Owner

Choose a reason for hiding this comment

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

Функция должна быть в отдельном файле

@@ -0,0 +1,16 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
Copy link
Owner

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() {
Copy link
Owner

Choose a reason for hiding this comment

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

Вы хотя бы тесты запускали?

Copy link
Author

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>>
Copy link
Owner

Choose a reason for hiding this comment

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

typealias должен быть в файле с функциями

Copy link
Author

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() {
Copy link
Owner

Choose a reason for hiding this comment

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

функция должна называться не init, а random, причем почему-то ограниченный до 10

Copy link
Author

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])
Copy link
Owner

Choose a reason for hiding this comment

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

для этого есть println

Copy link
Author

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) {
Copy link
Owner

Choose a reason for hiding this comment

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

зачем эта проверка?

Copy link
Author

Choose a reason for hiding this comment

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

я задумывал ее как проверку на то, что передаваемая матрциа не пустая

Copy link
Author

Choose a reason for hiding this comment

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

Зачем ее печатать если она пустая

Copy link
Owner

Choose a reason for hiding this comment

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

Тут судя по объявлению null никогда не будет. Я вам говорил про нулабилити элементы объявлены как не нулабл. если хотите проверять на то что матрица пустая, проверяйте по размеру

Copy link
Author

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) {
Copy link
Owner

Choose a reason for hiding this comment

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

аналогично, зачем эта проверка?

Copy link
Author

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) {
Copy link
Owner

Choose a reason for hiding this comment

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

Нужно выдавать ошибку (хотя бы печатать, а лучше кидать исключение), что размеры матриц не сходятся

Copy link
Author

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) {
Copy link
Owner

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) {
Copy link
Owner

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)
Copy link
Owner

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

Copy link
Author

Choose a reason for hiding this comment

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

Всмысле нужно эту функцию сделать не как расширение, а как отдельную функцию, которая будет возварщать значение?

@xthebat
Copy link
Owner

xthebat commented Sep 18, 2020

Опять в корень закомитили .gitignore

Copy link
Owner

@xthebat xthebat left a 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 {
Copy link
Owner

Choose a reason for hiding this comment

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

Должно быть сделано с использованием функций работы с коллекциями filter, map и т.п.

Copy link
Owner

@xthebat xthebat left a 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) {
Copy link
Owner

Choose a reason for hiding this comment

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

Тут судя по объявлению null никогда не будет. Я вам говорил про нулабилити элементы объявлены как не нулабл. если хотите проверять на то что матрица пустая, проверяйте по размеру

}
}
else {
throw IllegalArgumentException ("Неправильно заданы размеры матриц.")
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

Choose a reason for hiding this comment

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

можно использовать until

Добавлены тесты
Восстановил папки соучащихся
Удален дублирущий гитигнор файл
Разрешение конфликтов
1
1
@akhmetov-dev akhmetov-dev reopened this Nov 11, 2020
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.

2 participants