diff --git a/exercises/grade-school/Example.cs b/exercises/grade-school/Example.cs index 94dae228c4..efad1f1fc9 100644 --- a/exercises/grade-school/Example.cs +++ b/exercises/grade-school/Example.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -public class School +public class GradeSchool { private readonly Dictionary> roster = new Dictionary>(); diff --git a/exercises/grade-school/GradeSchool.cs b/exercises/grade-school/GradeSchool.cs index 9d9ccb82b0..957ca16db3 100644 --- a/exercises/grade-school/GradeSchool.cs +++ b/exercises/grade-school/GradeSchool.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -public class School +public class GradeSchool { public void Add(string student, int grade) { diff --git a/exercises/grade-school/GradeSchoolTest.cs b/exercises/grade-school/GradeSchoolTest.cs index 72402b6c2a..8cfd26e9cd 100644 --- a/exercises/grade-school/GradeSchoolTest.cs +++ b/exercises/grade-school/GradeSchoolTest.cs @@ -1,3 +1,6 @@ +// This file was auto-generated based on version 1.0.0 of the canonical data. + +using System; using Xunit; public class GradeSchoolTest @@ -5,81 +8,72 @@ public class GradeSchoolTest [Fact] public void Adding_a_student_adds_them_to_the_sorted_roster() { - var school = new School(); - school.Add("Aimee", 2); - - var actual = school.Roster(); - + var sut = new GradeSchool(); + sut.Add("Aimee", 2); var expected = new[] { "Aimee" }; - Assert.Equal(expected, actual); + Assert.Equal(expected, sut.Roster()); } [Fact(Skip = "Remove to run test")] - public void Adding_more_students_adds_them_to_the_sorted_roster() + public void Adding_more_student_adds_them_to_the_sorted_roster() { - var school = new School(); - school.Add("Blair", 2); - school.Add("James", 2); - school.Add("Paul", 2); - - var actual = school.Roster(); - + var sut = new GradeSchool(); + sut.Add("Blair", 2); + sut.Add("James", 2); + sut.Add("Paul", 2); var expected = new[] { "Blair", "James", "Paul" }; - Assert.Equal(expected, actual ); + Assert.Equal(expected, sut.Roster()); } [Fact(Skip = "Remove to run test")] public void Adding_students_to_different_grades_adds_them_to_the_same_sorted_roster() { - var school = new School(); - school.Add("Chelsea", 3); - school.Add("Logan", 7); - - var actual = school.Roster(); - - var expected = new[] { "Chelsea", "Logan"}; - Assert.Equal(expected, actual); + var sut = new GradeSchool(); + sut.Add("Chelsea", 3); + sut.Add("Logan", 7); + var expected = new[] { "Chelsea", "Logan" }; + Assert.Equal(expected, sut.Roster()); } [Fact(Skip = "Remove to run test")] - public void Grade_returns_the_students_in_that_grade_in_alphabetical_order() + public void Roster_returns_an_empty_list_if_there_are_no_students_enrolled() { - var school = new School(); - school.Add("Franklin", 5); - school.Add("Bradley", 5); - school.Add("Jeff", 1); - - var actual = school.Grade(5); - - var expected = new[] { "Bradley", "Franklin" }; - Assert.Equal(expected, actual); + var sut = new GradeSchool(); + var expected = Array.Empty(); + Assert.Empty(sut.Roster()); } [Fact(Skip = "Remove to run test")] - public void Grade_returns_an_empty_list_if_there_are_no_students_in_that_grade() + public void Student_names_with_grades_are_displayed_in_the_same_sorted_roster() { - var school = new School(); - - var actual = school.Grade(1); + var sut = new GradeSchool(); + sut.Add("Peter", 2); + sut.Add("Anna", 1); + sut.Add("Barb", 1); + sut.Add("Zoe", 2); + sut.Add("Alex", 2); + sut.Add("Jim", 3); + sut.Add("Charlie", 1); + var expected = new[] { "Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim" }; + Assert.Equal(expected, sut.Roster()); + } - Assert.Empty(actual); + [Fact(Skip = "Remove to run test")] + public void Grade_returns_the_students_in_that_grade_in_alphabetical_order() + { + var sut = new GradeSchool(); + sut.Add("Franklin", 5); + sut.Add("Bradley", 5); + sut.Add("Jeff", 1); + var expected = new[] { "Bradley", "Franklin" }; + Assert.Equal(expected, sut.Grade(5)); } [Fact(Skip = "Remove to run test")] - public void Student_names_with_grades_are_displayed_in_the_same_sorted_roster() + public void Grade_returns_an_empty_list_if_there_are_no_students_in_that_grade() { - var school = new School(); - school.Add("Peter", 2); - school.Add("Anna", 1); - school.Add("Barb", 1); - school.Add("Zoe", 2); - school.Add("Alex", 2); - school.Add("Jim", 3); - school.Add("Charlie", 1); - - var actual = school.Roster(); - - var expected = new[] { "Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim" }; - Assert.Equal(expected, actual); + var sut = new GradeSchool(); + var expected = Array.Empty(); + Assert.Empty(sut.Grade(1)); } } \ No newline at end of file diff --git a/generators/Exercises/Generators/GradeSchool.cs b/generators/Exercises/Generators/GradeSchool.cs new file mode 100644 index 0000000000..823bec19e5 --- /dev/null +++ b/generators/Exercises/Generators/GradeSchool.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Exercism.CSharp.Output; + +namespace Exercism.CSharp.Exercises.Generators +{ + public class GradeSchool : GeneratorExercise + { + protected override void UpdateTestMethod(TestMethod testMethod) + { + testMethod.UseVariableForExpected = true; + testMethod.TestedMethodType = TestedMethodType.InstanceMethod; + testMethod.InputParameters = testMethod.Input.ContainsKey("desiredGrade") + ? new[] { "desiredGrade" } + : Array.Empty(); + + testMethod.Arrange = RenderArrange(testMethod); + } + + private string RenderArrange(TestMethod testMethod) + { + var arrange = new StringBuilder(); + + arrange.AppendLine(Render.Variable("sut", "new GradeSchool()")); + + foreach (var student in testMethod.Input["students"]) + arrange.AppendLine($"sut.Add({Render.Object((string)student[0])}, {Render.Object(student[1])});"); + + arrange.AppendLine(Render.Variable("expected", Render.ObjectMultiLine(testMethod.Expected as string[] ?? Array.Empty()))); + + return arrange.ToString(); + } + + protected override void UpdateNamespaces(ISet namespaces) + { + namespaces.Add(typeof(Array).Namespace); + } + } +} \ No newline at end of file