Skip to content

Hw6#13

Open
GrigorySmirnovSpb wants to merge 17 commits into
mainfrom
HW6
Open

Hw6#13
GrigorySmirnovSpb wants to merge 17 commits into
mainfrom
HW6

Conversation

@GrigorySmirnovSpb

Copy link
Copy Markdown
Owner

Сделал 6 домашку. Написал тип MyTree, где дерево может иметь произвольное количество сыновей с помощью библиотеки FsharpPlus. Также к этому типу были написаны map, fold, foldBack и height. Они были также протестированы с помощью свойств.

Comment thread Test/TestsHw6.fs Outdated
if Single.IsFinite(a) && Single.IsFinite(b) then
abs (a - b) < epsilon
elif Single.IsNaN(a) && Single.IsNaN(b) then
true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А нельзя ли вот жто всё в одно логическое выражение записать?

Comment thread Test/TestsHw6.fs Outdated
elif Single.IsPositiveInfinity(a) && Single.IsPositiveInfinity(b) then
true
else
false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Точно через форматтер гоняли?

Comment thread Test/TestsHw6.fs Outdated
member _.floatTest(tree: MyTree<float32>) =
let treeList = MyTree.treeToList (MyTree.map id tree)
let list = MyTree.treeToList tree
Assert.True(List.forall2 (fun a b -> areAlmostEqual a b 1e-10f) list treeList)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

При id есть погрешность?

Comment thread Test/TestsHw6.fs Outdated
let sum acc value = value + acc
let actsum = MyTree.fold sum 0f tree
let expsum = List.fold (fun x acc -> sum acc x) 0f (MyTree.treeToList tree)
//Assert.True(areAlmostEqual actsum expsum 1e-10f)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Лишние комментарии?

Comment thread Test/TestsHw6.fs

[<Property>]
member _.floatFoldTest(tree: MyTree<float32>) =
let sum acc value = value + acc

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Добавьте тесты, которые покажут, что с ассоциативностью и фолдами всё хорошо.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Неплохо, но нужно провреить ещё и ассоциативность поэлементных операций.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Если я правильно понял, то это проверка ассоциативности map-а?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Нет. Речь именно про fold с операциями с различной ассоциативностью.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Хорошо, сейчас поправлю

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Т.е., нужно проверить ассоциативность функции sum которую я написал?

@GrigorySmirnovSpb
GrigorySmirnovSpb requested a review from gsvgit March 1, 2025 07:28
@gsvgit

gsvgit commented Mar 7, 2025

Copy link
Copy Markdown
Collaborator

И всё же, как проверить, что с операциями типа деления всё нормально?

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