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

math: add sum #29

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
math: add sum
  • Loading branch information
lareii committed Oct 25, 2023
commit 08307aa7d2beede0235b125d67ee6e5d302fd2b7
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
- [Max](./math/max.jule)
- [Median](./math/median.jule)
- [Min](./math/min.jule)
- [Sum](./math/sum.jule)

## Search
- [Binary Search](./search/binary_search.jule)
9 changes: 9 additions & 0 deletions math/sum.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn sum(slice: []int): int {
let mut total: int = 0

for _, i in slice {
total += i
}

ret total
}
1 change: 1 addition & 0 deletions tests/math/package_test.jule
Original file line number Diff line number Diff line change
@@ -6,4 +6,5 @@ pub fn math_package_tests(mut &tests: TestStack) {
max_tests(tests)
median_tests(tests)
min_tests(tests)
sum_tests(tests)
}
10 changes: 10 additions & 0 deletions tests/math/sum_test.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use tests::{TestStack}
use math::{sum}

fn sum_tests(mut &tests: TestStack) {
let slice = [-9, 0, 1, 99, 54, 12]

tests.add("[math] sum", fn(): bool {
ret sum(clone(slice)) == 157
})
}