Skip to content

Add Triangle Test Generator #423

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

Closed
jpreese opened this issue Sep 6, 2017 · 11 comments
Closed

Add Triangle Test Generator #423

jpreese opened this issue Sep 6, 2017 · 11 comments

Comments

@jpreese
Copy link
Contributor

jpreese commented Sep 6, 2017

This issue is part of an overall initiative to complete #195.

The documentation on how to add generators can be found here. If you get stuck or have any questions about adding this generator, please do not hesitate to reach out!

@bmeverett
Copy link
Contributor

I can take this one. Should the Generators.sln compile as soon as I add Exercises/Triangle.cs? Or will it only compile after I override UpdateConcicalData, although I set a break point and it doesn't even seem to be getting to the class but crashes when parsing the JSON.

@jpreese
Copy link
Contributor Author

jpreese commented Oct 2, 2017

Thanks for taking a look @bmeverett! The project should build as soon as you add Triangle.cs to the project. Make sure that you're inheriting from the Exercise base class.

@bmeverett
Copy link
Contributor

@jpreese sorry about that, it compiles but crashes when trying to generate the Triangle tests.

Sent with GitHawk

@jpreese
Copy link
Contributor Author

jpreese commented Oct 2, 2017

Thats no good. Can you provide some more information about the error that you're getting?

@bmeverett
Copy link
Contributor

Here is the stack trace of the error I'm getting

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Generators.Input.CanonicalDataCasesJson.IsEmptyJArray(CanonicalDataCase x, IGrouping`2 groupedProperties) in C:\Users\beverett\Documents\Github\csha
rp\generators\Input\CanonicalDataCasesJson.cs:line 56
   at Generators.Input.CanonicalDataCasesJson.<>c__DisplayClass4_0.<GetEmptyJArrays>b__0(CanonicalDataCase canonicalDataCase) in C:\Users\beverett\Documen
ts\Github\csharp\generators\Input\CanonicalDataCasesJson.cs:line 53
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at Generators.Input.CanonicalDataCasesJson.ConvertEmptyJArrayToArray(CanonicalDataCase[] canonicalDataCases) in C:\Users\beverett\Documents\Github\csha
rp\generators\Input\CanonicalDataCasesJson.cs:line 32
   at Generators.Input.CanonicalDataCasesJson.ToArray(JToken casesToken) in C:\Users\beverett\Documents\Github\csharp\generators\Input\CanonicalDataCasesJ
son.cs:line 17
   at Generators.Input.CanonicalDataCasesJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:
\Users\beverett\Documents\Github\csharp\generators\Input\CanonicalDataCasesJsonConverter.cs:line 13
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Objec
t existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerCon
tract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProp
erty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty memb
er, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Generators.Input.CanonicalDataParser.Parse(Exercise exercise) in C:\Users\beverett\Documents\Github\csharp\generators\Input\CanonicalDataParser.cs:l
ine 19
   at Generators.Program.RegenerateTestClasses(Options options) in C:\Users\beverett\Documents\Github\csharp\generators\Program.cs:line 44
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at Generators.Program.Main(String[] args) in C:\Users\beverett\Documents\Github\csharp\generators\Program.cs:line 18

@jpreese
Copy link
Contributor Author

jpreese commented Oct 2, 2017

So this is the code I have for Traingle.cs (added it to Generators/Exercises/Triangle.cs), I didn't change anything else.

using System;
using System.Collections.Generic;
using System.Text;

namespace Generators.Exercises
{
    public class Triangle : Exercise
    {
    }
}

If this matches what you have and still errors, could you push the branch that gives you this error? I'll be able to check it out and debug locally.

@bmeverett
Copy link
Contributor

Pushed to https://github.com/bmeverett/csharp/tree/423-triangle-generator and I copied and pasted what you had and it still errors

@jpreese
Copy link
Contributor Author

jpreese commented Oct 2, 2017

Awesome thanks! It looks like your branch is a little behind. We made some changes to the generator framework recently, so you'll want to pull those in.

I checked out your branch and was able to reproduce the issue. After merging in master, everything worked.

@bmeverett
Copy link
Contributor

Thank you! That did it!

@bmeverett
Copy link
Contributor

So I think the triangle data is throwing me off.

Property- equilateral this isn't a property of the class, I get that it's supposed to be TriangleKind.Equilateral
sides- the sides is an array, do we need to break this up or change the class to input an array as a parameter
expected value - true/false should we return the enum value here?

I guess I would think the property should be Kind and then the expected value should be one of the eunm values? Let me know if this makes sense or I'm totally missing something.

@ErikSchierboom
Copy link
Member

@bmeverett Great observation. What I think we should do is to modify our stub and example implementation to drop the enum and simplify add three boolean tests: scalene, isosceles and equilateral (and perhaps add a more idiomatic IsScalene, IsIsosceles and IsEquilateral). In most cases it makes sense to just follow the canonical data, and I think mapping this canonical data to a format where an enum is used will actually be quite hard.

By the way, as the canonical data descriptions are overlapping, you'll need to use the full description path as the test method name (to make the method names unique). This is possible since the merge of this commit, so I would recommend rebasing to the latest master if that commit is not in your history. Once it is, you can set the UseFullDescriptionPath to true to use the full path (see this line for an example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants