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

Hw6 #13

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Hw6 #13

wants to merge 17 commits into from

Conversation

GrigorySmirnovSpb
Copy link
Owner

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

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
Collaborator

Choose a reason for hiding this comment

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

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

Test/TestsHw6.fs Outdated
elif Single.IsPositiveInfinity(a) && Single.IsPositiveInfinity(b) then
true
else
false
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

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
Collaborator

Choose a reason for hiding this comment

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

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

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
Collaborator

Choose a reason for hiding this comment

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

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


[<Property>]
member _.floatFoldTest(tree: MyTree<float32>) =
let sum acc value = value + acc
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

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

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

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

gsvgit commented Mar 7, 2025

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

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