Skip to content

Grade School: Update exercise and fix test structure #1959

@andrerfcsantos

Description

@andrerfcsantos

There was some work done to improve the Grade School exercise in the problem specification repo (exercism/problem-specifications#1837).

Update

We want to update our version of grade school to match the latest problem spec version: https://github.com/exercism/problem-specifications/tree/main/exercises/grade-school

This involves ...

Fix Test Structure

The current test cases are done in a very ad-hoc way. While you are making sure that the test cases fit the canonical data, please also ensure all test cases are structured in an AAA (Arrange Act Assert) pattern like we are doing in the other exercises.

This is an example of the tests we have now:

func TestAddStudent(t *testing.T) {
	exp := list([]Grade{{2, []string{"Aimee"}}})
	s := New()
	s.Add("Aimee", 2)
	got := list(s.Enrollment())
	if got != exp {
		t.Errorf(`Add Aimee level 2, got
%sexpected:
%s`, got, exp)
	}
}

The target structure is:

  1. A slice with all the test cases. It's ok to have different test cases for each test function.
  2. A for range loop iterating over the test cases, acting on them and checking the result.

This is an example of a test suite of another exercise following the desired pattern: blackjack_test.go

Advantages of doing this:

  • More maintainable tests
  • Test code can be properly picked up by the test-runner

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions