Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion exercises/grade-school/Example.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;

public class School
public class GradeSchool
{
private readonly Dictionary<int, IList<string>> roster = new Dictionary<int, IList<string>>();

Expand Down
2 changes: 1 addition & 1 deletion exercises/grade-school/GradeSchool.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

public class School
public class GradeSchool
{
public void Add(string student, int grade)
{
Expand Down
98 changes: 46 additions & 52 deletions exercises/grade-school/GradeSchoolTest.cs
Original file line number Diff line number Diff line change
@@ -1,85 +1,79 @@
// This file was auto-generated based on version 1.0.0 of the canonical data.

using System;
using Xunit;

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<string>();
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<string>();
Assert.Empty(sut.Grade(1));
}
}
40 changes: 40 additions & 0 deletions generators/Exercises/Generators/GradeSchool.cs
Original file line number Diff line number Diff line change
@@ -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<string>();

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<string>())));

return arrange.ToString();
}

protected override void UpdateNamespaces(ISet<string> namespaces)
{
namespaces.Add(typeof(Array).Namespace);
}
}
}