From 23a041da215c547a5c3bf278e0ac2930b96020c3 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Sat, 11 Mar 2017 02:25:52 -0800 Subject: [PATCH 1/4] pov: Add exercise, version, cases, description, comments, property At this point, if only the `trees` key were to be deleted, this file would conform to the schema as desired by #625. We will need to delete the `trees` key using the plan set out in #699. --- exercises/pov/canonical-data.json | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/exercises/pov/canonical-data.json b/exercises/pov/canonical-data.json index 98ad17ddc7..b93e001191 100644 --- a/exercises/pov/canonical-data.json +++ b/exercises/pov/canonical-data.json @@ -1,7 +1,9 @@ { - "from_pov": { - "description": [ - "Reroot a tree so that its root is the specified node.", + "exercise": "pov", + "version": "1.0.0", + "cases": [{ + "description": "Reroot a tree so that its root is the specified node.", + "comments": [ "In this way, the tree is presented from the point of view of the specified node.", "The input trees used here are those in the `trees` section of this file.", "", @@ -17,6 +19,7 @@ "cases": [ { "description": "Results in the same tree if the input tree is a singleton", + "property": "fromPov", "tree": "singleton", "from": "x", "expected": { @@ -25,6 +28,7 @@ }, { "description": "Can reroot a tree with a parent and one sibling", + "property": "fromPov", "tree": "simple", "from": "x", "expected": { @@ -43,6 +47,7 @@ }, { "description": "Can reroot a tree with a parent and many siblings", + "property": "fromPov", "tree": "large_flat", "from": "x", "expected": { @@ -67,6 +72,7 @@ }, { "description": "Can reroot a tree with new root deeply nested in tree", + "property": "fromPov", "tree": "deeply_nested", "from": "x", "expected": { @@ -95,6 +101,7 @@ }, { "description": "Moves children of the new root to same level as former parent", + "property": "fromPov", "tree": "kids", "from": "x", "expected": { @@ -114,6 +121,7 @@ }, { "description": "Can reroot a complex tree with cousins", + "property": "fromPov", "tree": "cousins", "from": "x", "expected": { @@ -157,21 +165,22 @@ }, { "description": "Errors if target does not exist in a singleton tree", + "property": "fromPov", "tree": "singleton", "from": "nonexistent", "expected": null }, { "description": "Errors if target does not exist in a large tree", + "property": "fromPov", "tree": "cousins", "from": "nonexistent", "expected": null } ] - }, - "path_to": { - "description": [ - "Given two nodes, find the path between them.", + }, { + "description": "Given two nodes, find the path between them", + "comments": [ "A typical implementation would first reroot the tree on one of the two nodes.", "", "If appropriate for your track, you may test that the input tree is not modified.", @@ -181,6 +190,7 @@ "cases": [ { "description": "Can find path to parent", + "property": "pathTo", "from": "x", "to": "parent", "tree": "simple", @@ -191,6 +201,7 @@ }, { "description": "Can find path to sibling", + "property": "pathTo", "from": "x", "to": "b", "tree": "large_flat", @@ -202,6 +213,7 @@ }, { "description": "Can find path to cousin", + "property": "pathTo", "from": "x", "to": "cousin-1", "tree": "cousins", @@ -215,6 +227,7 @@ }, { "description": "Can find path from nodes other than x", + "property": "pathTo", "from": "kid-1", "to": "cousin-0", "tree": "cousins", @@ -229,6 +242,7 @@ }, { "description": "Errors if destination does not exist", + "property": "pathTo", "from": "x", "to": "nonexistent", "tree": "cousins", @@ -236,13 +250,14 @@ }, { "description": "Errors if source does not exist", + "property": "pathTo", "from": "nonexistent", "to": "x", "tree": "cousins", "expected": null } ] - }, + }], "trees": { "singleton": { "label": "x" From 17b29e6cdbdd25fd3a02d9af4ac76a9048126cfe Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Sat, 11 Mar 2017 02:32:37 -0800 Subject: [PATCH 2/4] pov: Embed all NON-cousins trees into individual cases In #699 we discussed that referring to trees by name rather than embedding has a few costs: * Requires schema change. * `shared` or `resources` section must be exercise-dependent by nature. * More complex test generators. * Harder for a human to understand the test (must refer back and forth between the individual case and the "trees" listing). We have decided this is not worth it. Extra work on the `cousins` tree is required to reduce its usage, so it will not yet be embedded. --- exercises/pov/canonical-data.json | 179 +++++++++++++++++------------- 1 file changed, 101 insertions(+), 78 deletions(-) diff --git a/exercises/pov/canonical-data.json b/exercises/pov/canonical-data.json index b93e001191..a6f7c7d2b5 100644 --- a/exercises/pov/canonical-data.json +++ b/exercises/pov/canonical-data.json @@ -20,7 +20,9 @@ { "description": "Results in the same tree if the input tree is a singleton", "property": "fromPov", - "tree": "singleton", + "tree": { + "label": "x" + }, "from": "x", "expected": { "label": "x" @@ -29,7 +31,17 @@ { "description": "Can reroot a tree with a parent and one sibling", "property": "fromPov", - "tree": "simple", + "tree": { + "label": "parent", + "children": [ + { + "label": "x" + }, + { + "label": "sibling" + } + ] + }, "from": "x", "expected": { "label": "x", @@ -48,7 +60,23 @@ { "description": "Can reroot a tree with a parent and many siblings", "property": "fromPov", - "tree": "large_flat", + "tree": { + "label": "parent", + "children": [ + { + "label": "a" + }, + { + "label": "x" + }, + { + "label": "b" + }, + { + "label": "c" + } + ] + }, "from": "x", "expected": { "label": "x", @@ -73,7 +101,29 @@ { "description": "Can reroot a tree with new root deeply nested in tree", "property": "fromPov", - "tree": "deeply_nested", + "tree": { + "label": "level-0", + "children": [ + { + "label": "level-1", + "children": [ + { + "label": "level-2", + "children": [ + { + "label": "level-3", + "children": [ + { + "label": "x" + } + ] + } + ] + } + ] + } + ] + }, "from": "x", "expected": { "label": "x", @@ -102,7 +152,22 @@ { "description": "Moves children of the new root to same level as former parent", "property": "fromPov", - "tree": "kids", + "tree": { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + } + ] + }, "from": "x", "expected": { "label": "x", @@ -166,7 +231,9 @@ { "description": "Errors if target does not exist in a singleton tree", "property": "fromPov", - "tree": "singleton", + "tree": { + "label": "x" + }, "from": "nonexistent", "expected": null }, @@ -193,7 +260,17 @@ "property": "pathTo", "from": "x", "to": "parent", - "tree": "simple", + "tree": { + "label": "parent", + "children": [ + { + "label": "x" + }, + { + "label": "sibling" + } + ] + }, "expected": [ "x", "parent" @@ -204,7 +281,23 @@ "property": "pathTo", "from": "x", "to": "b", - "tree": "large_flat", + "tree": { + "label": "parent", + "children": [ + { + "label": "a" + }, + { + "label": "x" + }, + { + "label": "b" + }, + { + "label": "c" + } + ] + }, "expected": [ "x", "parent", @@ -259,76 +352,6 @@ ] }], "trees": { - "singleton": { - "label": "x" - }, - "simple": { - "label": "parent", - "children": [ - { - "label": "x" - }, - { - "label": "sibling" - } - ] - }, - "large_flat": { - "label": "parent", - "children": [ - { - "label": "a" - }, - { - "label": "x" - }, - { - "label": "b" - }, - { - "label": "c" - } - ] - }, - "deeply_nested": { - "label": "level-0", - "children": [ - { - "label": "level-1", - "children": [ - { - "label": "level-2", - "children": [ - { - "label": "level-3", - "children": [ - { - "label": "x" - } - ] - } - ] - } - ] - } - ] - }, - "kids": { - "label": "parent", - "children": [ - { - "label": "x", - "children": [ - { - "label": "kid-0" - }, - { - "label": "kid-1" - } - ] - } - ] - }, "cousins": { "label": "grandparent", "children": [ From 2d1c6805de052864e804a420055723f0bb55ca51 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Sat, 11 Mar 2017 02:40:37 -0800 Subject: [PATCH 3/4] pov 1.1.0: replace unnecessary uses of "cousins" tree with smaller tree We would like to reduce the tree so that: 1. It's clearer what is being tested 2. The duplication in the test file is kept to fewer lines This helps us be rid of the top-level `"trees"` key as desired in #699. The usages of "cousin" that were replaced: **Three error cases**: 1. "Errors if target does not exist in a large tree" 2. "Errors if destination does not exist" 3. "Errors if source does not exist" In all three cases, a "large" tree is all that is necessary. It doesn't necessarily have to be the entire "cousin" tree. Besides, it's not very interesting to see whether a student can *fail* to find a nonexistent node in a large tree, because the student can just as easily achieve it by not doing any searching at all. It's much more intersting to see whether the student can find an existent node in a large tree. So these error cases really don't need a very large tree. A "large" tree is all that is needed, but it doesn't necessarily have to so big so as to be the entire "cousin" tree. **One case of "Can find path from nodes other than x"**: Nothing in this case requires the use of the specific "cousins" tree. Since the test contents have now changed, this is now version 1.1.0. --- exercises/pov/canonical-data.json | 100 ++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 12 deletions(-) diff --git a/exercises/pov/canonical-data.json b/exercises/pov/canonical-data.json index a6f7c7d2b5..96a565f1f1 100644 --- a/exercises/pov/canonical-data.json +++ b/exercises/pov/canonical-data.json @@ -1,6 +1,6 @@ { "exercise": "pov", - "version": "1.0.0", + "version": "1.1.0", "cases": [{ "description": "Reroot a tree so that its root is the specified node.", "comments": [ @@ -240,7 +240,28 @@ { "description": "Errors if target does not exist in a large tree", "property": "fromPov", - "tree": "cousins", + "tree": { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + }, + { + "label": "sibling-0" + }, + { + "label": "sibling-1" + } + ] + }, "from": "nonexistent", "expected": null } @@ -321,16 +342,29 @@ { "description": "Can find path from nodes other than x", "property": "pathTo", - "from": "kid-1", - "to": "cousin-0", - "tree": "cousins", + "from": "a", + "to": "c", + "tree": { + "label": "parent", + "children": [ + { + "label": "a" + }, + { + "label": "x" + }, + { + "label": "b" + }, + { + "label": "c" + } + ] + }, "expected": [ - "kid-1", - "x", + "a", "parent", - "grandparent", - "uncle", - "cousin-0" + "c" ] }, { @@ -338,7 +372,28 @@ "property": "pathTo", "from": "x", "to": "nonexistent", - "tree": "cousins", + "tree": { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + }, + { + "label": "sibling-0" + }, + { + "label": "sibling-1" + } + ] + }, "expected": null }, { @@ -346,7 +401,28 @@ "property": "pathTo", "from": "nonexistent", "to": "x", - "tree": "cousins", + "tree": { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + }, + { + "label": "sibling-0" + }, + { + "label": "sibling-1" + } + ] + }, "expected": null } ] From edd01e28aa19a62d80767d8283416b6b55a3deb8 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Sat, 11 Mar 2017 02:45:06 -0800 Subject: [PATCH 4/4] pov: embed cousins tree into remaining usages This concludes the `pov` portion of #699. This finally brings the `pov` exercise's JSON file in compliance with the schema, concluding the relevant portion of #625. --- exercises/pov/canonical-data.json | 120 +++++++++++++++++++----------- 1 file changed, 77 insertions(+), 43 deletions(-) diff --git a/exercises/pov/canonical-data.json b/exercises/pov/canonical-data.json index 96a565f1f1..9cbe37dc8a 100644 --- a/exercises/pov/canonical-data.json +++ b/exercises/pov/canonical-data.json @@ -187,7 +187,44 @@ { "description": "Can reroot a complex tree with cousins", "property": "fromPov", - "tree": "cousins", + "tree": { + "label": "grandparent", + "children": [ + { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + }, + { + "label": "sibling-0" + }, + { + "label": "sibling-1" + } + ] + }, + { + "label": "uncle", + "children": [ + { + "label": "cousin-0" + }, + { + "label": "cousin-1" + } + ] + } + ] + }, "from": "x", "expected": { "label": "x", @@ -330,7 +367,44 @@ "property": "pathTo", "from": "x", "to": "cousin-1", - "tree": "cousins", + "tree": { + "label": "grandparent", + "children": [ + { + "label": "parent", + "children": [ + { + "label": "x", + "children": [ + { + "label": "kid-0" + }, + { + "label": "kid-1" + } + ] + }, + { + "label": "sibling-0" + }, + { + "label": "sibling-1" + } + ] + }, + { + "label": "uncle", + "children": [ + { + "label": "cousin-0" + }, + { + "label": "cousin-1" + } + ] + } + ] + }, "expected": [ "x", "parent", @@ -426,45 +500,5 @@ "expected": null } ] - }], - "trees": { - "cousins": { - "label": "grandparent", - "children": [ - { - "label": "parent", - "children": [ - { - "label": "x", - "children": [ - { - "label": "kid-0" - }, - { - "label": "kid-1" - } - ] - }, - { - "label": "sibling-0" - }, - { - "label": "sibling-1" - } - ] - }, - { - "label": "uncle", - "children": [ - { - "label": "cousin-0" - }, - { - "label": "cousin-1" - } - ] - } - ] - } - } + }] }