-
-
Notifications
You must be signed in to change notification settings - Fork 365
423 triangle generator #458
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
Merged
ErikSchierboom
merged 4 commits into
exercism:master
from
bmeverett:423-triangle-generator
Oct 4, 2017
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5a1bb0
update Triangle example and class
bmeverett fce678c
update triangle generator and triangle example
bmeverett dfc71cb
update types in example to match Triangle.cs
bmeverett 5268e24
update everything to use double and make sure tests pass
bmeverett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,108 @@ | ||
// This file was auto-generated based on version 1.0.0 of the canonical data. | ||
|
||
using Xunit; | ||
|
||
public class TriangleTest | ||
{ | ||
[Fact] | ||
public void Equilateral_triangles_have_equal_sides() | ||
public void Returns_true_if_the_triangle_is_equilateral_true_if_all_sides_are_equal() | ||
{ | ||
Assert.True(Triangle.IsEquilateral(2,2,2)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Returns_true_if_the_triangle_is_equilateral_false_if_any_side_is_unequal() | ||
{ | ||
Assert.False(Triangle.IsEquilateral(2,3,2)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Returns_true_if_the_triangle_is_equilateral_false_if_no_sides_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Equilateral, Triangle.Kind(2, 2, 2)); | ||
Assert.False(Triangle.IsEquilateral(5,4,6)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Larger_equilateral_triangles_also_have_equal_sides() | ||
public void Returns_true_if_the_triangle_is_equilateral_all_zero_sides_are_illegal_so_the_triangle_is_not_equilateral() | ||
{ | ||
Assert.Equal(TriangleKind.Equilateral, Triangle.Kind(10, 10, 10)); | ||
Assert.False(Triangle.IsEquilateral(0,0,0)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Isosceles_triangles_have_last_two_sides_equal() | ||
public void Returns_true_if_the_triangle_is_equilateral_sides_may_be_floats() | ||
{ | ||
Assert.Equal(TriangleKind.Isosceles, Triangle.Kind(3, 4, 4)); | ||
Assert.True(Triangle.IsEquilateral(0.5,0.5,0.5)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Isosceles_triangles_have_first_and_last_sides_equal() | ||
public void Returns_true_if_the_triangle_is_isosceles_true_if_last_two_sides_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Isosceles, Triangle.Kind(4, 3, 4)); | ||
Assert.True(Triangle.IsIsosceles(3,4,4)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Isosceles_triangles_have_two_first_sides_equal() | ||
public void Returns_true_if_the_triangle_is_isosceles_true_if_first_two_sides_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Isosceles, Triangle.Kind(4, 4, 3)); | ||
Assert.True(Triangle.IsIsosceles(4,4,3)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Isosceles_triangles_have_in_fact_exactly_two_sides_equal() | ||
public void Returns_true_if_the_triangle_is_isosceles_true_if_first_and_last_sides_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Isosceles, Triangle.Kind(10, 10, 2)); | ||
Assert.True(Triangle.IsIsosceles(4,3,4)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Scalene_triangles_have_no_equal_sides() | ||
public void Returns_true_if_the_triangle_is_isosceles_equilateral_triangles_are_also_isosceles() | ||
{ | ||
Assert.Equal(TriangleKind.Scalene, Triangle.Kind(3, 4, 5)); | ||
Assert.True(Triangle.IsIsosceles(4,4,4)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Scalene_triangles_have_no_equal_sides_at_a_larger_scale_too() | ||
public void Returns_true_if_the_triangle_is_isosceles_false_if_no_sides_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Scalene, Triangle.Kind(10, 11, 12)); | ||
Assert.False(Triangle.IsIsosceles(2,3,4)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Scalene_triangles_have_no_equal_sides_in_descending_order_either() | ||
public void Returns_true_if_the_triangle_is_isosceles_sides_that_violate_triangle_inequality_are_not_isosceles_even_if_two_are_equal() | ||
{ | ||
Assert.Equal(TriangleKind.Scalene, Triangle.Kind(5, 4, 2)); | ||
Assert.False(Triangle.IsIsosceles(1,1,3)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Very_small_triangles_are_legal() | ||
public void Returns_true_if_the_triangle_is_isosceles_sides_may_be_floats() | ||
{ | ||
Assert.Equal(TriangleKind.Scalene, Triangle.Kind(0.4m, 0.6m, 0.3m)); | ||
Assert.True(Triangle.IsIsosceles(0.5,0.4,0.5)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Triangles_with_no_size_are_illegal() | ||
public void Returns_true_if_the_triangle_is_scalene_true_if_no_sides_are_equal() | ||
{ | ||
Assert.Throws<TriangleException>(() => Triangle.Kind(0, 0, 0)); | ||
Assert.True(Triangle.IsScalene(5,4,6)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Triangles_with_negative_sides_are_illegal() | ||
public void Returns_true_if_the_triangle_is_scalene_false_if_all_sides_are_equal() | ||
{ | ||
Assert.Throws<TriangleException>(() => Triangle.Kind(3, 4, -5)); | ||
Assert.False(Triangle.IsScalene(4,4,4)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Triangles_violating_triangle_inequality_are_illegal() | ||
public void Returns_true_if_the_triangle_is_scalene_false_if_two_sides_are_equal() | ||
{ | ||
Assert.Throws<TriangleException>(() => Triangle.Kind(1, 1, 3)); | ||
Assert.False(Triangle.IsScalene(4,4,3)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Triangles_violating_triangle_inequality_are_illegal_2() | ||
public void Returns_true_if_the_triangle_is_scalene_sides_that_violate_triangle_inequality_are_not_scalene_even_if_they_are_all_different() | ||
{ | ||
Assert.Throws<TriangleException>(() => Triangle.Kind(2, 4, 2)); | ||
Assert.False(Triangle.IsScalene(7,3,2)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Triangles_violating_triangle_inequality_are_illegal_3() | ||
public void Returns_true_if_the_triangle_is_scalene_sides_may_be_floats() | ||
{ | ||
Assert.Throws<TriangleException>(() => Triangle.Kind(7, 3, 2)); | ||
Assert.True(Triangle.IsScalene(0.5,0.4,0.6)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Generators.Input; | ||
using Generators.Output; | ||
namespace Generators.Exercises | ||
{ | ||
public class Triangle : Exercise | ||
{ | ||
protected override void UpdateCanonicalData(CanonicalData canonicalData) | ||
{ | ||
foreach (var data in canonicalData.Cases) | ||
{ | ||
if (data.Property == "equilateral") | ||
data.Property = "IsEquilateral"; | ||
else if (data.Property == "isosceles") | ||
data.Property = "IsIsosceles"; | ||
else if (data.Property == "scalene") | ||
data.Property = "IsScalene"; | ||
|
||
data.Properties["sides"] = SplitArrayToValues(data.Properties["sides"]); | ||
data.SetInputParameters("sides"); | ||
data.UseFullDescriptionPath = true; | ||
|
||
} | ||
} | ||
|
||
private UnescapedValue SplitArrayToValues(IEnumerable input) | ||
{ | ||
const string template = "{% for item in {{input}} %}{{item}}{% if forloop.last == false %},{% endif %}{% endfor %}"; | ||
|
||
return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); | ||
} | ||
|
||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be consistent, we should keep the types used here and in
Example.cs
the same.