-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
All tracks that have test generators #155
Comments
This was my biggest pain point when I wrote the generator for Vimscript. As you said, I'm essentially guessing. I remove the keys It's easy to see that this approach is very fragile, nonetheless it works in a lot of cases. I intended to open an issue for this for But you also raised other points I didn't encounter, e.g. type issues, so I hope we can compile a list of typical issues here and use those to create a standard for canonical data. This would make generators less complex and more correct. |
The VimScript approach in that regard so far is brilliant... remove the known keys, use the unknown. |
I need to clarify this and why I am interested in the answer to this question. In some JSON parsers in statically-typed languages, you must declare the types of all key/value pairs in a JSON object before you can parse it. This poses a challenge for, say, the An excerpt: "cases": [
{
"description": "Create a new clock with an initial time",
"cases": [
{
"description": "on the hour",
"property": "create",
"hour": 8,
"minute": 0,
"expected": "08:00"
}
]
},
{
"description": "Add minutes",
"cases": [
{
"description": "add minutes",
"property": "add",
"hour": 10,
"minute": 0,
"add": 3,
"expected": "10:03"
}
]
},
{
"description": "Compare two clocks for equality",
"cases": [
{
"description": "clocks with same time",
"property": "equal",
"clock1": {
"hour": 15,
"minute": 37
},
"clock2": {
"hour": 15,
"minute": 37
},
"expected": true
}
]
}
] Well, since the There will now be some examples in Go, but you might imagine how you would do it in your statically-typed language of choice. The current solution at https://github.com/exercism/xgo/blob/master/exercises/clock/.meta/gen.go is to union all the keys/values. type js struct {
Groups TestGroups `json:"Cases"`
}
type TestGroups []struct {
Description string
Cases []OneCase
}
type OneCase struct {
Description string
Property string
Hour int // "create"/"add" cases
Minute int // "create"/"add" cases
Add int // "add" cases only
Clock1 struct{ Hour, Minute int } // "equal" cases only
Clock2 struct{ Hour, Minute int } // "equal" cases only
Expected interface{} // string or bool
} How does this compare to the state of the world before "create": {
"description": [
"Test creating a new clock with an initial time."
],
"cases": [
{
"description": "on the hour",
"hour": 8,
"minute": 0,
"expected": "08:00"
}
]
},
"add": {
"description": [
"Test adding and subtracting minutes."
],
"cases": [
{
"description": "add minutes",
"hour": 10,
"minute": 0,
"add": 3,
"expected": "10:03"
}
]
},
"equal": {
"description": [
"Construct two separate clocks, set times, test if they are equal."
],
"cases": [
{
"description": "clocks with same time",
"clock1": {
"hour": 15,
"minute": 37
},
"clock2": {
"hour": 15,
"minute": 37
},
"expected": true
}
]
} To this, it is possible to use the structure at https://github.com/exercism/xgo/blob/d8dbcece4b6bbdd8f82099645c4defa02daca2c0/exercises/clock/.meta/gen.go type js struct {
Create struct {
Description []string
Cases []struct {
Description string
Hour, Minute int
Expected string
}
}
Add struct {
Description []string
Cases []struct {
Description string
Hour, Minute, Add int
Expected string
}
}
Equal struct {
Description []string
Cases []struct {
Description string
Clock1, Clock2 struct{ Hour, Minute int }
Expected bool
}
}
} Let's remind everyone of why we moved away from this approach: exercism/problem-specifications#336 (comment) :
So what do we do? If you think this problem is insurmountable, then you might think to propose a schema change.
There are of course various choices NOT involving schema changes! If every language wanting to parse the JSON finds at least one of these choices satisfactory, the schema doesn't need to change for this reason (it might change for other reasons).
|
The use of prior knowledge has already required me to make changes to the test the last time The approach I intend to take instead is a for @($c-data<cases>) {
for @(.<cases>) -> $case {
given $case<property> {
when 'create' {
...
}
when 'add' {
...
}
when 'equal' {
...
}
}
}
}
|
@petertseng is it a goal for all tracks to implement test generators? |
I won't presume to speak for Exercism (and I shouldn't answer at all because you aren't asking me, you are asking peter seng, but I will answer anyway), but I can say for sure it's not one of my goals. Each track can do as its maintainers please. Whatever makes their lives easier. |
Way overdue. Reminder that exercism/problem-specifications#996 should make it easy to determine what the inputs are. |
Welcome to another issue of "All tracks that have X".
Today's issue is about test generators.
These are anything that use the canonical-data.json file from x-common and generate a test suite to be delivered to students of a given track.
If your track has these, I would be interested to hear about it.
I hope this can help tracks that don't have generators evaluate whether to have them, and allow tracks that already have generators to learn from each other.
Questions I would like to ask:
expected
as the output is known, but the input values take on many different names.comments
,description
,expected
,property
(TBD: tests that take multiple inputs). See Add lib/generate.vim vimscript#32.property
key?property
is read, then parse into different structs depending on whatproperty
is.This issue may be closed when, in the issue-closer's opinion, there has been enough discussion to get an idea of how some tracks are answering these questions. Of course, even after it is closed, please feel free to comment with any additional answers.
If as a result there are any proposed changes to the schema, an appropriate issue can be created for that.
To give us a head start, here is what I know of some languages' generators.
Please forgive me for being greedy and filling in information for tracks that I am unfamiliar with.
Please correct these or add any additional tracks I missed.
In alphabetical order:
C#
property
: https://github.com/exercism/xcsharp/blob/master/generators/Exercises/BeerSongExercise.csIDictionary<string, object>
, supporting values of any type.ColdFusion
Factor
Go
.meta/gen.go
in each exercise directory defines the structure that the file is expected to have.property
first before the other key/value pairs.JavaScript
OCaml
Perl 6
cases
): https://github.com/exercism/xperl6/blob/master/exercises/clock/example.yaml and https://github.com/exercism/xperl6/blob/master/exercises/clock/clock.tRuby
bin
directory: https://github.com/exercism/xruby/blob/master/bin/generatelib/generator
providing common-case parsing: https://github.com/exercism/xruby/tree/master/lib/generator.meta/generator
in each exercise directory containing a*_case.rb
file. If necessary a customtest_template.erb
can be provided. Most tests use a common default templateEdit: Most tests use a common default template.
Rust
Scala
Vimscript
The text was updated successfully, but these errors were encountered: