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

Tooling and CI set up + 1st four exercises #25

Merged
merged 24 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
41c644f
hello-word, leap, configuration updates
gvrooyen Aug 23, 2024
4f70d44
Add workflow in test.yml
gvrooyen Aug 23, 2024
27d56ac
Modified CI workflow to build Odin from source
gvrooyen Aug 23, 2024
c7fb86e
Completed difference-of-squares, added format-all
gvrooyen Aug 24, 2024
6d31497
Formatted source, added formatting to webhook
gvrooyen Aug 24, 2024
aa92d6e
Added step to push autoformatting changes
gvrooyen Aug 24, 2024
92817bc
Modified test.yml to not fail on no formatting
gvrooyen Aug 24, 2024
17ef99f
Added missing dashes in argument
gvrooyen Aug 24, 2024
5cf8060
Fixed bin/verify-exercises
gvrooyen Aug 24, 2024
0024848
Added the "grains" exercise
gvrooyen Aug 25, 2024
48c2bbe
Updated README; fixed test verification
gvrooyen Aug 25, 2024
11a21ff
Formatted config files with configlet
gvrooyen Aug 26, 2024
3ffcf58
Fixed testing bug that clobbered stub solutions
gvrooyen Aug 26, 2024
97b7017
Small code fixes. Updated README.
gvrooyen Aug 26, 2024
fd4c5d1
Added resistor-color exercise. Updated README.
gvrooyen Aug 26, 2024
cfbb1b8
Fixed and tested the test.yml action
gvrooyen Aug 27, 2024
deb0858
Implemented the resistor-color exercise
gvrooyen Aug 27, 2024
3ea8588
Removed configlet dependency in test.yml
gvrooyen Aug 27, 2024
9cd2286
Moved the exercise checklist to a linked GH issue
gvrooyen Aug 28, 2024
2a8d7cc
Test runner now checks that stub solution fails
gvrooyen Aug 28, 2024
0d5ecdd
Fixed incorrect stubs, added panics for stub procs
gvrooyen Aug 28, 2024
585abb5
Removed fancy terminal color commands
gvrooyen Aug 28, 2024
5f81ce0
Added support for skipping and unskipping tests
gvrooyen Aug 29, 2024
1bf9d9c
Removed mention of NotImplemented in the README
gvrooyen Aug 30, 2024
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
14 changes: 12 additions & 2 deletions bin/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@ function run_test() {
# "exercises/practice/.meta/hello_world_example.odin"
example_file="${exercise_path}/${meta}/${exercise_safe_name}_example.odin"

# Copy the example and test files into the temporary directory
# Copy the example file into the temporary directory
cp ${example_file} ${tmp_path}/${exercise_safe_name}.odin
cp ${test_file} ${tmp_path}

# Unskip all tests and write the processed test file to the temporary directory.
# The test file for the exercise often has several of the tests skippped initially, so that
# students can do test-driven development by enabling the next test, possibly see it fail,
# and then refining their solution. However, the test runner used by contributors and the CI
# pipeline always needs to run all tests.
#
# In Odin, a test can be skipped by commenting out the `@(test)` annotation preceding the
# test procedure. Here we unskip the test by searching for `\\ @(test)` lines and replacing
# them with `@test`.
sed s/"\/\/ @(test)"/"@(test)"/ ${test_file} > ${tmp_path}/${exercise_safe_name}_test.odin

# Run the tests using the example file to verify that it is a valid solution.
odin test ${tmp_path}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* These are the unit tests for the exercise. Only the first one is enabled to start with. You can
* enable the other tests by uncommenting the `@(test)` attribute of the test procedure. Your
* solution should pass all tests before it is ready for submission.
*/

package difference_of_squares

import "core:testing"
Expand All @@ -7,42 +12,42 @@ test_square_of_sum_1 :: proc(t: ^testing.T) {
testing.expect_value(t, square_of_sum(1), 1)
}

@(test)
// @(test)
test_square_of_sum_5 :: proc(t: ^testing.T) {
testing.expect_value(t, square_of_sum(5), 225)
}

@(test)
// @(test)
test_square_of_sum_100 :: proc(t: ^testing.T) {
testing.expect_value(t, square_of_sum(100), 25_502_500)
}

@(test)
// @(test)
sum_of_squares_1_test :: proc(t: ^testing.T) {
testing.expect_value(t, sum_of_squares(1), 1)
}

@(test)
// @(test)
sum_of_squares_5_test :: proc(t: ^testing.T) {
testing.expect_value(t, sum_of_squares(5), 55)
}

@(test)
// @(test)
sum_of_squares_100_test :: proc(t: ^testing.T) {
testing.expect_value(t, sum_of_squares(100), 338_350)
}

@(test)
// @(test)
difference_of_squares_1_test :: proc(t: ^testing.T) {
testing.expect_value(t, difference(1), 0)
}

@(test)
// @(test)
difference_of_squares_5_test :: proc(t: ^testing.T) {
testing.expect_value(t, difference(5), 170)
}

@(test)
// @(test)
difference_of_squares_100_test :: proc(t: ^testing.T) {
testing.expect_value(t, difference(100), 25_164_150)
}
25 changes: 15 additions & 10 deletions exercises/practice/grains/grains_test.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* These are the unit tests for the exercise. Only the first one is enabled to start with. You can
* enable the other tests by uncommenting the `@(test)` attribute of the test procedure. Your
* solution should pass all tests before it is ready for submission.
*/

package grains

import "core:testing"
Expand All @@ -11,7 +16,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_1 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_2 :: proc(
t: ^testing.T,
) {
Expand All @@ -20,7 +25,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_2 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_3 :: proc(
t: ^testing.T,
) {
Expand All @@ -29,7 +34,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_3 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_4 :: proc(
t: ^testing.T,
) {
Expand All @@ -38,7 +43,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_4 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_16 :: proc(
t: ^testing.T,
) {
Expand All @@ -47,7 +52,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_16 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_32 :: proc(
t: ^testing.T,
) {
Expand All @@ -56,7 +61,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_32 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_grains_on_square_64 :: proc(
t: ^testing.T,
) {
Expand All @@ -65,7 +70,7 @@ test_returns_the_number_of_grains_on_the_square_grains_on_square_64 :: proc(
testing.expect_value(t, e, Error.None)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_square_0_raises_an_exception :: proc(
t: ^testing.T,
) {
Expand All @@ -74,7 +79,7 @@ test_returns_the_number_of_grains_on_the_square_square_0_raises_an_exception ::
testing.expect_value(t, e, Error.InvalidSquare)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_negative_square_raises_an_exception :: proc(
t: ^testing.T,
) {
Expand All @@ -83,7 +88,7 @@ test_returns_the_number_of_grains_on_the_square_negative_square_raises_an_except
testing.expect_value(t, e, Error.InvalidSquare)
}

@(test)
// @(test)
test_returns_the_number_of_grains_on_the_square_square_greater_than_64_raises_an_exception :: proc(
t: ^testing.T,
) {
Expand All @@ -92,7 +97,7 @@ test_returns_the_number_of_grains_on_the_square_square_greater_than_64_raises_an
testing.expect_value(t, e, Error.InvalidSquare)
}

@(test)
// @(test)
test_returns_the_total_number_of_grains_on_the_board :: proc(t: ^testing.T) {
c, e := total()
testing.expect_value(t, c, 18_446_744_073_709_551_615)
Expand Down
21 changes: 13 additions & 8 deletions exercises/practice/leap/leap_test.odin
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* These are the unit tests for the exercise. Only the first one is enabled to start with. You can
* enable the other tests by uncommenting the `@(test)` attribute of the test procedure. Your
* solution should pass all tests before it is ready for submission.
*/
gvrooyen marked this conversation as resolved.
Show resolved Hide resolved

package leap

import "core:testing"
Expand All @@ -7,48 +12,48 @@ test_not_divisible_by_4_in_common_year :: proc(t: ^testing.T) {
testing.expect(t, !is_leap_year(2015))
}

@(test)
// @(test)
test_divisible_by_2_not_divisible_by_4_in_common_year :: proc(t: ^testing.T) {
testing.expect(t, !is_leap_year(1970))
}

@(test)
// @(test)
test_divisible_by_4_not_divisible_by_100_in_leap_year :: proc(t: ^testing.T) {
testing.expect(t, is_leap_year(1996))
}

@(test)
// @(test)
test_divisible_by_4_and_5_is_still_a_leap_year :: proc(t: ^testing.T) {
testing.expect(t, is_leap_year(1960))
}

@(test)
// @(test)
test_divisible_by_100_not_divisible_by_400_in_common_year :: proc(
t: ^testing.T,
) {
testing.expect(t, !is_leap_year(2100))
}

@(test)
// @(test)
test_divisible_by_100_but_not_by_3_is_still_not_a_leap_year :: proc(
t: ^testing.T,
) {
testing.expect(t, !is_leap_year(1900))
}

@(test)
// @(test)
test_divisible_by_400 :: proc(t: ^testing.T) {
testing.expect(t, is_leap_year(2000))
}

@(test)
// @(test)
test_divisible_by_400_but_not_by_125_is_still_a_leap_year :: proc(
t: ^testing.T,
) {
testing.expect(t, is_leap_year(2400))
}

@(test)
// @(test)
test_divisible_by_200_not_divisible_by_400_in_common_year :: proc(
t: ^testing.T,
) {
Expand Down
8 changes: 7 additions & 1 deletion exercises/practice/resistor-color/resistor_color_test.odin
gvrooyen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* These are the unit tests for the exercise. Only the tests for the `code()`
* procedure are enabled to start with. You can enable the final test by
* uncommenting the`@(test)` attribute of the `all_colors` test procedure. Your
* solution should pass all tests before it is ready for submission.
*/

package resistor_color

import "core:testing"
Expand Down Expand Up @@ -52,7 +58,7 @@ white :: proc(t: ^testing.T) {
testing.expect_value(t, code(.White), 9)
}

@(test)
// @(test)
all_colors :: proc(t: ^testing.T) {
testing.expect_value(
t,
Expand Down