From c528d9e4f66df08fa14dc03b5793f65a40a25668 Mon Sep 17 00:00:00 2001 From: oxe-i Date: Fri, 6 Feb 2026 08:53:49 -0300 Subject: [PATCH] adjust generator --- exercises/practice/house/HouseTest.lean | 71 +++++-- .../RelativeDistanceTest.lean | 183 +++++++++++++++++- generators/GenerateTestFile.lean | 4 +- generators/Generator/Generator.lean | 4 +- .../Generator/Generator/AcronymGenerator.lean | 2 +- .../Generator/AllYourBaseGenerator.lean | 2 +- .../Generator/AllergiesGenerator.lean | 2 +- .../Generator/Generator/AnagramGenerator.lean | 2 +- .../Generator/ArmstrongNumbersGenerator.lean | 2 +- .../Generator/AtbashCipherGenerator.lean | 2 +- .../Generator/BinarySearchGenerator.lean | 2 +- .../Generator/Generator/CamiciaGenerator.lean | 2 +- .../Generator/Generator/ClockGenerator.lean | 2 +- .../Generator/CollatzConjectureGenerator.lean | 2 +- .../Generator/ComplexNumbersGenerator.lean | 2 +- .../Generator/Generator/ConnectGenerator.lean | 2 +- .../Generator/CryptoSquareGenerator.lean | 2 +- .../Generator/DominoesGenerator.lean | 46 +++++ .../Generator/Generator/EtlGenerator.lean | 2 +- .../Generator/Generator/ForthGenerator.lean | 2 +- .../Generator/GameOfLifeGenerator.lean | 2 +- .../Generator/GigasecondGenerator.lean | 2 +- .../Generator/Generator/GrainsGenerator.lean | 2 +- .../Generator/Generator/GrepGenerator.lean | 2 +- .../Generator/HighScoresGenerator.lean | 2 +- .../Generator/Generator/HouseGenerator.lean | 8 +- .../Generator/Generator/LeapGenerator.lean | 2 +- .../PalindromeProductsGenerator.lean | 2 +- .../ParallelLetterFrequencyGenerator.lean | 2 +- .../Generator/PerfectNumbersGenerator.lean | 2 +- .../Generator/PhoneNumberGenerator.lean | 2 +- .../Generator/PrimeFactorsGenerator.lean | 2 +- .../ProteinTranslationGenerator.lean | 2 +- .../PythagoreanTripletGenerator.lean | 2 +- .../Generator/RailFenceCipherGenerator.lean | 2 +- .../Generator/RationalNumbersGenerator.lean | 2 +- .../Generator/RectanglesGenerator.lean | 2 +- .../Generator/RelativeDistanceGenerator.lean | 11 +- .../Generator/RomanNumeralsGenerator.lean | 2 +- .../Generator/Generator/SayGenerator.lean | 2 +- .../Generator/SecretHandshakeGenerator.lean | 2 +- .../Generator/Generator/SeriesGenerator.lean | 2 +- .../Generator/SpaceAgeGenerator.lean | 2 +- .../Generator/Generator/SublistGenerator.lean | 2 +- .../Generator/TransposeGenerator.lean | 2 +- .../Generator/TriangleGenerator.lean | 2 +- .../Generator/TwoBucketGenerator.lean | 2 +- .../Generator/Generator/WordyGenerator.lean | 2 +- .../Generator/Generator/YachtGenerator.lean | 2 +- generators/Generator/Helper.lean | 46 ++++- 50 files changed, 370 insertions(+), 87 deletions(-) create mode 100644 generators/Generator/Generator/DominoesGenerator.lean diff --git a/exercises/practice/house/HouseTest.lean b/exercises/practice/house/HouseTest.lean index f6a8c65..865c349 100644 --- a/exercises/practice/house/HouseTest.lean +++ b/exercises/practice/house/HouseTest.lean @@ -6,33 +6,76 @@ open LeanTest def houseTests : TestSuite := (TestSuite.empty "House") |>.addTest "verse one - the house that jack built" (do - return assertEqual (String.intercalate "\n\n" ["This is the house that Jack built."]) (House.recite ⟨1, by decide⟩ ⟨1, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the house that Jack built." + ]) (House.recite ⟨1, by decide⟩ ⟨1, by decide⟩)) |>.addTest "verse two - the malt that lay" (do - return assertEqual (String.intercalate "\n\n" ["This is the malt that lay in the house that Jack built."]) (House.recite ⟨2, by decide⟩ ⟨2, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the malt that lay in the house that Jack built." + ]) (House.recite ⟨2, by decide⟩ ⟨2, by decide⟩)) |>.addTest "verse three - the rat that ate" (do - return assertEqual (String.intercalate "\n\n" ["This is the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨3, by decide⟩ ⟨3, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨3, by decide⟩ ⟨3, by decide⟩)) |>.addTest "verse four - the cat that killed" (do - return assertEqual (String.intercalate "\n\n" ["This is the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨4, by decide⟩ ⟨4, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨4, by decide⟩ ⟨4, by decide⟩)) |>.addTest "verse five - the dog that worried" (do - return assertEqual (String.intercalate "\n\n" ["This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨5, by decide⟩ ⟨5, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨5, by decide⟩ ⟨5, by decide⟩)) |>.addTest "verse six - the cow with the crumpled horn" (do - return assertEqual (String.intercalate "\n\n" ["This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨6, by decide⟩ ⟨6, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨6, by decide⟩ ⟨6, by decide⟩)) |>.addTest "verse seven - the maiden all forlorn" (do - return assertEqual (String.intercalate "\n\n" ["This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨7, by decide⟩ ⟨7, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨7, by decide⟩ ⟨7, by decide⟩)) |>.addTest "verse eight - the man all tattered and torn" (do - return assertEqual (String.intercalate "\n\n" ["This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨8, by decide⟩ ⟨8, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨8, by decide⟩ ⟨8, by decide⟩)) |>.addTest "verse nine - the priest all shaven and shorn" (do - return assertEqual (String.intercalate "\n\n" ["This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨9, by decide⟩ ⟨9, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨9, by decide⟩ ⟨9, by decide⟩)) |>.addTest "verse 10 - the rooster that crowed in the morn" (do - return assertEqual (String.intercalate "\n\n" ["This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨10, by decide⟩ ⟨10, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨10, by decide⟩ ⟨10, by decide⟩)) |>.addTest "verse 11 - the farmer sowing his corn" (do - return assertEqual (String.intercalate "\n\n" ["This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨11, by decide⟩ ⟨11, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨11, by decide⟩ ⟨11, by decide⟩)) |>.addTest "verse 12 - the horse and the hound and the horn" (do - return assertEqual (String.intercalate "\n\n" ["This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨12, by decide⟩ ⟨12, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨12, by decide⟩ ⟨12, by decide⟩)) |>.addTest "multiple verses" (do - return assertEqual (String.intercalate "\n\n" ["This is the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨4, by decide⟩ ⟨8, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨4, by decide⟩ ⟨8, by decide⟩)) |>.addTest "full rhyme" (do - return assertEqual (String.intercalate "\n\n" ["This is the house that Jack built.", "This is the malt that lay in the house that Jack built.", "This is the rat that ate the malt that lay in the house that Jack built.", "This is the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."]) (House.recite ⟨1, by decide⟩ ⟨12, by decide⟩)) + return assertEqual (String.intercalate "\n\n" [ + "This is the house that Jack built.", + "This is the malt that lay in the house that Jack built.", + "This is the rat that ate the malt that lay in the house that Jack built.", + "This is the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.", + "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built." + ]) (House.recite ⟨1, by decide⟩ ⟨12, by decide⟩)) def main : IO UInt32 := do runTestSuitesWithExitCode [houseTests] diff --git a/exercises/practice/relative-distance/RelativeDistanceTest.lean b/exercises/practice/relative-distance/RelativeDistanceTest.lean index 5147b53..4e44025 100644 --- a/exercises/practice/relative-distance/RelativeDistanceTest.lean +++ b/exercises/practice/relative-distance/RelativeDistanceTest.lean @@ -6,19 +6,188 @@ open LeanTest def relativeDistanceTests : TestSuite := (TestSuite.empty "RelativeDistance") |>.addTest "Direct parent-child relation" (do - return assertEqual (some 1) (RelativeDistance.degreeOfSeparation [("Tomoko", ["Aditi"]), ("Vera", ["Tomoko"])] "Vera" "Tomoko")) + return assertEqual (some 1) (RelativeDistance.degreeOfSeparation [ + ("Tomoko", ["Aditi"]), + ("Vera", ["Tomoko"]) + ] "Vera" "Tomoko")) |>.addTest "Sibling relationship" (do - return assertEqual (some 1) (RelativeDistance.degreeOfSeparation [("Dalia", ["Olga","Yassin"])] "Olga" "Yassin")) + return assertEqual (some 1) (RelativeDistance.degreeOfSeparation [ + ("Dalia", ["Olga", "Yassin"]) + ] "Olga" "Yassin")) |>.addTest "Two degrees of separation, grandchild" (do - return assertEqual (some 2) (RelativeDistance.degreeOfSeparation [("Khadija", ["Mateo"]), ("Mateo", ["Rami"])] "Khadija" "Rami")) + return assertEqual (some 2) (RelativeDistance.degreeOfSeparation [ + ("Khadija", ["Mateo"]), + ("Mateo", ["Rami"]) + ] "Khadija" "Rami")) |>.addTest "Unrelated individuals" (do - return assertEqual none (RelativeDistance.degreeOfSeparation [("Kaito", ["Elif"]), ("Priya", ["Rami"])] "Priya" "Kaito")) + return assertEqual none (RelativeDistance.degreeOfSeparation [ + ("Kaito", ["Elif"]), + ("Priya", ["Rami"]) + ] "Priya" "Kaito")) |>.addTest "Complex graph, cousins" (do - return assertEqual (some 9) (RelativeDistance.degreeOfSeparation [("Aditi", ["Nia"]), ("Nia", ["Antonio"]), ("Aiko", ["Bao","Carlos"]), ("Bao", ["Dalia","Elias"]), ("Carlos", ["Fatima","Gustavo"]), ("Dalia", ["Hassan","Isla"]), ("Elias", ["Javier"]), ("Boris", ["Oscar"]), ("Oscar", ["Bianca"]), ("Fatima", ["Khadija","Liam"]), ("Gustavo", ["Mina"]), ("Celine", ["Priya"]), ("Priya", ["Cai"]), ("Hassan", ["Noah","Olga"]), ("Isla", ["Pedro"]), ("Diego", ["Qi"]), ("Qi", ["Dimitri"]), ("Javier", ["Quynh","Ravi"]), ("Elif", ["Rami"]), ("Rami", ["Ewa"]), ("Farah", ["Sven"]), ("Sven", ["Fabio"]), ("Khadija", ["Sofia"]), ("Liam", ["Tariq","Uma"]), ("Giorgio", ["Tomoko"]), ("Tomoko", ["Gabriela"]), ("Mina", ["Viktor","Wang"]), ("Hana", ["Umar"]), ("Umar", ["Helena"]), ("Uma", ["Giorgio"]), ("Noah", ["Xiomara"]), ("Olga", ["Yuki"]), ("Ian", ["Vera"]), ("Vera", ["Igor"]), ("Pedro", ["Zane","Aditi"]), ("Quynh", ["Boris"]), ("Ravi", ["Celine"]), ("Jing", ["Wyatt"]), ("Wyatt", ["Jun"]), ("Kaito", ["Xia"]), ("Xia", ["Kim"]), ("Sofia", ["Diego","Elif"]), ("Leila", ["Yassin"]), ("Yassin", ["Lucia"]), ("Tariq", ["Farah"]), ("Mateo", ["Zara"]), ("Zara", ["Mohammed"]), ("Viktor", ["Hana","Ian"]), ("Wang", ["Jing"]), ("Xiomara", ["Kaito"]), ("Yuki", ["Leila"]), ("Zane", ["Mateo"])] "Dimitri" "Fabio")) + return assertEqual (some 9) (RelativeDistance.degreeOfSeparation [ + ("Aditi", ["Nia"]), + ("Aiko", ["Bao", "Carlos"]), + ("Bao", ["Dalia", "Elias"]), + ("Boris", ["Oscar"]), + ("Carlos", ["Fatima", "Gustavo"]), + ("Celine", ["Priya"]), + ("Dalia", ["Hassan", "Isla"]), + ("Diego", ["Qi"]), + ("Elias", ["Javier"]), + ("Elif", ["Rami"]), + ("Farah", ["Sven"]), + ("Fatima", ["Khadija", "Liam"]), + ("Giorgio", ["Tomoko"]), + ("Gustavo", ["Mina"]), + ("Hana", ["Umar"]), + ("Hassan", ["Noah", "Olga"]), + ("Ian", ["Vera"]), + ("Isla", ["Pedro"]), + ("Javier", ["Quynh", "Ravi"]), + ("Jing", ["Wyatt"]), + ("Kaito", ["Xia"]), + ("Khadija", ["Sofia"]), + ("Leila", ["Yassin"]), + ("Liam", ["Tariq", "Uma"]), + ("Mateo", ["Zara"]), + ("Mina", ["Viktor", "Wang"]), + ("Nia", ["Antonio"]), + ("Noah", ["Xiomara"]), + ("Olga", ["Yuki"]), + ("Oscar", ["Bianca"]), + ("Pedro", ["Zane", "Aditi"]), + ("Priya", ["Cai"]), + ("Qi", ["Dimitri"]), + ("Quynh", ["Boris"]), + ("Rami", ["Ewa"]), + ("Ravi", ["Celine"]), + ("Sofia", ["Diego", "Elif"]), + ("Sven", ["Fabio"]), + ("Tariq", ["Farah"]), + ("Tomoko", ["Gabriela"]), + ("Uma", ["Giorgio"]), + ("Umar", ["Helena"]), + ("Vera", ["Igor"]), + ("Viktor", ["Hana", "Ian"]), + ("Wang", ["Jing"]), + ("Wyatt", ["Jun"]), + ("Xia", ["Kim"]), + ("Xiomara", ["Kaito"]), + ("Yassin", ["Lucia"]), + ("Yuki", ["Leila"]), + ("Zane", ["Mateo"]), + ("Zara", ["Mohammed"]) + ] "Dimitri" "Fabio")) |>.addTest "Complex graph, no shortcut, far removed nephew" (do - return assertEqual (some 14) (RelativeDistance.degreeOfSeparation [("Aditi", ["Nia"]), ("Nia", ["Antonio"]), ("Aiko", ["Bao","Carlos"]), ("Bao", ["Dalia","Elias"]), ("Carlos", ["Fatima","Gustavo"]), ("Dalia", ["Hassan","Isla"]), ("Elias", ["Javier"]), ("Boris", ["Oscar"]), ("Oscar", ["Bianca"]), ("Fatima", ["Khadija","Liam"]), ("Gustavo", ["Mina"]), ("Celine", ["Priya"]), ("Priya", ["Cai"]), ("Hassan", ["Noah","Olga"]), ("Isla", ["Pedro"]), ("Diego", ["Qi"]), ("Qi", ["Dimitri"]), ("Javier", ["Quynh","Ravi"]), ("Elif", ["Rami"]), ("Rami", ["Ewa"]), ("Farah", ["Sven"]), ("Sven", ["Fabio"]), ("Khadija", ["Sofia"]), ("Liam", ["Tariq","Uma"]), ("Giorgio", ["Tomoko"]), ("Tomoko", ["Gabriela"]), ("Mina", ["Viktor","Wang"]), ("Hana", ["Umar"]), ("Umar", ["Helena"]), ("Uma", ["Giorgio"]), ("Noah", ["Xiomara"]), ("Olga", ["Yuki"]), ("Ian", ["Vera"]), ("Vera", ["Igor"]), ("Pedro", ["Zane","Aditi"]), ("Quynh", ["Boris"]), ("Ravi", ["Celine"]), ("Jing", ["Wyatt"]), ("Wyatt", ["Jun"]), ("Kaito", ["Xia"]), ("Xia", ["Kim"]), ("Sofia", ["Diego","Elif"]), ("Leila", ["Yassin"]), ("Yassin", ["Lucia"]), ("Tariq", ["Farah"]), ("Mateo", ["Zara"]), ("Zara", ["Mohammed"]), ("Viktor", ["Hana","Ian"]), ("Wang", ["Jing"]), ("Xiomara", ["Kaito"]), ("Yuki", ["Leila"]), ("Zane", ["Mateo"])] "Lucia" "Jun")) + return assertEqual (some 14) (RelativeDistance.degreeOfSeparation [ + ("Aditi", ["Nia"]), + ("Aiko", ["Bao", "Carlos"]), + ("Bao", ["Dalia", "Elias"]), + ("Boris", ["Oscar"]), + ("Carlos", ["Fatima", "Gustavo"]), + ("Celine", ["Priya"]), + ("Dalia", ["Hassan", "Isla"]), + ("Diego", ["Qi"]), + ("Elias", ["Javier"]), + ("Elif", ["Rami"]), + ("Farah", ["Sven"]), + ("Fatima", ["Khadija", "Liam"]), + ("Giorgio", ["Tomoko"]), + ("Gustavo", ["Mina"]), + ("Hana", ["Umar"]), + ("Hassan", ["Noah", "Olga"]), + ("Ian", ["Vera"]), + ("Isla", ["Pedro"]), + ("Javier", ["Quynh", "Ravi"]), + ("Jing", ["Wyatt"]), + ("Kaito", ["Xia"]), + ("Khadija", ["Sofia"]), + ("Leila", ["Yassin"]), + ("Liam", ["Tariq", "Uma"]), + ("Mateo", ["Zara"]), + ("Mina", ["Viktor", "Wang"]), + ("Nia", ["Antonio"]), + ("Noah", ["Xiomara"]), + ("Olga", ["Yuki"]), + ("Oscar", ["Bianca"]), + ("Pedro", ["Zane", "Aditi"]), + ("Priya", ["Cai"]), + ("Qi", ["Dimitri"]), + ("Quynh", ["Boris"]), + ("Rami", ["Ewa"]), + ("Ravi", ["Celine"]), + ("Sofia", ["Diego", "Elif"]), + ("Sven", ["Fabio"]), + ("Tariq", ["Farah"]), + ("Tomoko", ["Gabriela"]), + ("Uma", ["Giorgio"]), + ("Umar", ["Helena"]), + ("Vera", ["Igor"]), + ("Viktor", ["Hana", "Ian"]), + ("Wang", ["Jing"]), + ("Wyatt", ["Jun"]), + ("Xia", ["Kim"]), + ("Xiomara", ["Kaito"]), + ("Yassin", ["Lucia"]), + ("Yuki", ["Leila"]), + ("Zane", ["Mateo"]), + ("Zara", ["Mohammed"]) + ] "Lucia" "Jun")) |>.addTest "Complex graph, some shortcuts, cross-down and cross-up, cousins several times removed, with unrelated family tree" (do - return assertEqual (some 12) (RelativeDistance.degreeOfSeparation [("Aditi", ["Nia"]), ("Nia", ["Antonio"]), ("Aiko", ["Bao","Carlos"]), ("Bao", ["Dalia"]), ("Carlos", ["Fatima","Gustavo"]), ("Dalia", ["Hassan","Isla"]), ("Boris", ["Oscar"]), ("Oscar", ["Bianca"]), ("Fatima", ["Khadija","Liam"]), ("Gustavo", ["Mina"]), ("Celine", ["Priya"]), ("Priya", ["Cai"]), ("Hassan", ["Noah","Olga"]), ("Isla", ["Pedro"]), ("Diego", ["Qi"]), ("Qi", ["Dimitri"]), ("Elif", ["Rami"]), ("Rami", ["Ewa"]), ("Farah", ["Sven"]), ("Sven", ["Fabio"]), ("Khadija", ["Sofia"]), ("Liam", ["Tariq","Uma"]), ("Giorgio", ["Tomoko"]), ("Tomoko", ["Gabriela"]), ("Mina", ["Viktor","Wang"]), ("Hana", ["Umar"]), ("Umar", ["Helena"]), ("Uma", ["Giorgio"]), ("Noah", ["Xiomara"]), ("Olga", ["Yuki"]), ("Ian", ["Vera"]), ("Vera", ["Igor"]), ("Pedro", ["Zane","Aditi"]), ("Javier", ["Quynh","Ravi"]), ("Quynh", ["Boris"]), ("Ravi", ["Celine"]), ("Jing", ["Wyatt"]), ("Wyatt", ["Jun"]), ("Kaito", ["Xia"]), ("Xia", ["Kim"]), ("Sofia", ["Diego","Elif"]), ("Leila", ["Yassin"]), ("Yassin", ["Lucia"]), ("Tariq", ["Farah"]), ("Mateo", ["Zara"]), ("Zara", ["Mohammed"]), ("Viktor", ["Hana","Ian"]), ("Wang", ["Jing"]), ("Xiomara", ["Kaito"]), ("Yuki", ["Leila"]), ("Zane", ["Mateo"])] "Wyatt" "Xia")) + return assertEqual (some 12) (RelativeDistance.degreeOfSeparation [ + ("Aditi", ["Nia"]), + ("Aiko", ["Bao", "Carlos"]), + ("Bao", ["Dalia"]), + ("Boris", ["Oscar"]), + ("Carlos", ["Fatima", "Gustavo"]), + ("Celine", ["Priya"]), + ("Dalia", ["Hassan", "Isla"]), + ("Diego", ["Qi"]), + ("Elif", ["Rami"]), + ("Farah", ["Sven"]), + ("Fatima", ["Khadija", "Liam"]), + ("Giorgio", ["Tomoko"]), + ("Gustavo", ["Mina"]), + ("Hana", ["Umar"]), + ("Hassan", ["Noah", "Olga"]), + ("Ian", ["Vera"]), + ("Isla", ["Pedro"]), + ("Javier", ["Quynh", "Ravi"]), + ("Jing", ["Wyatt"]), + ("Kaito", ["Xia"]), + ("Khadija", ["Sofia"]), + ("Leila", ["Yassin"]), + ("Liam", ["Tariq", "Uma"]), + ("Mateo", ["Zara"]), + ("Mina", ["Viktor", "Wang"]), + ("Nia", ["Antonio"]), + ("Noah", ["Xiomara"]), + ("Olga", ["Yuki"]), + ("Oscar", ["Bianca"]), + ("Pedro", ["Zane", "Aditi"]), + ("Priya", ["Cai"]), + ("Qi", ["Dimitri"]), + ("Quynh", ["Boris"]), + ("Rami", ["Ewa"]), + ("Ravi", ["Celine"]), + ("Sofia", ["Diego", "Elif"]), + ("Sven", ["Fabio"]), + ("Tariq", ["Farah"]), + ("Tomoko", ["Gabriela"]), + ("Uma", ["Giorgio"]), + ("Umar", ["Helena"]), + ("Vera", ["Igor"]), + ("Viktor", ["Hana", "Ian"]), + ("Wang", ["Jing"]), + ("Wyatt", ["Jun"]), + ("Xia", ["Kim"]), + ("Xiomara", ["Kaito"]), + ("Yassin", ["Lucia"]), + ("Yuki", ["Leila"]), + ("Zane", ["Mateo"]), + ("Zara", ["Mohammed"]) + ] "Wyatt" "Xia")) def main : IO UInt32 := do runTestSuitesWithExitCode [relativeDistanceTests] diff --git a/generators/GenerateTestFile.lean b/generators/GenerateTestFile.lean index b1379c3..00d095b 100644 --- a/generators/GenerateTestFile.lean +++ b/generators/GenerateTestFile.lean @@ -1,5 +1,5 @@ import Std -import Lean +import Lean.Data.Json import Generator open Lean @@ -250,7 +250,7 @@ def regenerateTestFiles : IO Unit := do def generateStub (exercise : String) : IO Unit := do let pascalExercise := pascalCase exercise let content := -s!"import Lean +s!"import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator.lean b/generators/Generator/Generator.lean index 75a2163..f9832f7 100644 --- a/generators/Generator/Generator.lean +++ b/generators/Generator/Generator.lean @@ -1,3 +1,4 @@ +import Generator.DominoesGenerator import Generator.HighScoresGenerator import Generator.SublistGenerator import Generator.RelativeDistanceGenerator @@ -44,7 +45,7 @@ import Generator.TriangleGenerator import Generator.AnagramGenerator import Std -import Lean +import Lean.Data.Json namespace Generator @@ -54,6 +55,7 @@ abbrev endBodyGenerator := String -> String def dispatch : Std.HashMap String (introGenerator × testCaseGenerator × endBodyGenerator) := Std.HashMap.ofList [ + ("Dominoes", (DominoesGenerator.genIntro, DominoesGenerator.genTestCase, DominoesGenerator.genEnd)), ("HighScores", (HighScoresGenerator.genIntro, HighScoresGenerator.genTestCase, HighScoresGenerator.genEnd)), ("Sublist", (SublistGenerator.genIntro, SublistGenerator.genTestCase, SublistGenerator.genEnd)), ("RelativeDistance", (RelativeDistanceGenerator.genIntro, RelativeDistanceGenerator.genTestCase, RelativeDistanceGenerator.genEnd)), diff --git a/generators/Generator/Generator/AcronymGenerator.lean b/generators/Generator/Generator/AcronymGenerator.lean index cdbd22a..f4e3ca1 100644 --- a/generators/Generator/Generator/AcronymGenerator.lean +++ b/generators/Generator/Generator/AcronymGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/AllYourBaseGenerator.lean b/generators/Generator/Generator/AllYourBaseGenerator.lean index 4235a2c..e94d333 100644 --- a/generators/Generator/Generator/AllYourBaseGenerator.lean +++ b/generators/Generator/Generator/AllYourBaseGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/AllergiesGenerator.lean b/generators/Generator/Generator/AllergiesGenerator.lean index df6aa19..b2198aa 100644 --- a/generators/Generator/Generator/AllergiesGenerator.lean +++ b/generators/Generator/Generator/AllergiesGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/AnagramGenerator.lean b/generators/Generator/Generator/AnagramGenerator.lean index 78d7ed5..f5e693d 100644 --- a/generators/Generator/Generator/AnagramGenerator.lean +++ b/generators/Generator/Generator/AnagramGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/ArmstrongNumbersGenerator.lean b/generators/Generator/Generator/ArmstrongNumbersGenerator.lean index d71372b..775edfe 100644 --- a/generators/Generator/Generator/ArmstrongNumbersGenerator.lean +++ b/generators/Generator/Generator/ArmstrongNumbersGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/AtbashCipherGenerator.lean b/generators/Generator/Generator/AtbashCipherGenerator.lean index 5c6c16b..0a0c3c5 100644 --- a/generators/Generator/Generator/AtbashCipherGenerator.lean +++ b/generators/Generator/Generator/AtbashCipherGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/BinarySearchGenerator.lean b/generators/Generator/Generator/BinarySearchGenerator.lean index 613f4cb..12b5214 100644 --- a/generators/Generator/Generator/BinarySearchGenerator.lean +++ b/generators/Generator/Generator/BinarySearchGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/CamiciaGenerator.lean b/generators/Generator/Generator/CamiciaGenerator.lean index e75deac..17bf9a8 100644 --- a/generators/Generator/Generator/CamiciaGenerator.lean +++ b/generators/Generator/Generator/CamiciaGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/ClockGenerator.lean b/generators/Generator/Generator/ClockGenerator.lean index 280de6c..6cdd7f9 100644 --- a/generators/Generator/Generator/ClockGenerator.lean +++ b/generators/Generator/Generator/ClockGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/CollatzConjectureGenerator.lean b/generators/Generator/Generator/CollatzConjectureGenerator.lean index a7c57f6..5e51572 100644 --- a/generators/Generator/Generator/CollatzConjectureGenerator.lean +++ b/generators/Generator/Generator/CollatzConjectureGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/ComplexNumbersGenerator.lean b/generators/Generator/Generator/ComplexNumbersGenerator.lean index c6840ba..6e827c9 100644 --- a/generators/Generator/Generator/ComplexNumbersGenerator.lean +++ b/generators/Generator/Generator/ComplexNumbersGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/ConnectGenerator.lean b/generators/Generator/Generator/ConnectGenerator.lean index 4468395..ff1a5a1 100644 --- a/generators/Generator/Generator/ConnectGenerator.lean +++ b/generators/Generator/Generator/ConnectGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/CryptoSquareGenerator.lean b/generators/Generator/Generator/CryptoSquareGenerator.lean index ba10f80..9b0d1d4 100644 --- a/generators/Generator/Generator/CryptoSquareGenerator.lean +++ b/generators/Generator/Generator/CryptoSquareGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/DominoesGenerator.lean b/generators/Generator/Generator/DominoesGenerator.lean new file mode 100644 index 0000000..1be97be --- /dev/null +++ b/generators/Generator/Generator/DominoesGenerator.lean @@ -0,0 +1,46 @@ +import Lean.Data.Json +import Std +import Helper + +open Lean +open Std +open Helper + +namespace DominoesGenerator + +def genIntro (exercise : String) : String := s!"import LeanTest +import {exercise} + +open LeanTest + +def {exercise.decapitalize}Tests : TestSuite := + (TestSuite.empty \"{exercise}\")" + +def serializer (domino : Json) : String := + let array := domino.getArr? |> getOk + let first := array[0]! + let second := array[1]! + s!"(⟨{first}, by decide⟩, ⟨{second}, by decide⟩)" + +def genTestCase (exercise : String) (case : TreeMap.Raw String Json) : String := + let dominoes := case.get! "input" |>.getObjVal? "dominoes" |> getOk + let expected := case.get! "expected" |>.getBool? |> getOk + let description := case.get! "description" + |> (·.compress) + let funName := getFunName (case.get! "property") + let call := s!"({exercise}.{funName} {serializeList dominoes serializer})" + let assert := match expected with + | true => s!"assertTrue {call}" + | false => s!"assertFalse {call}" + s!" + |>.addTest {description} (do + return {assert})" + +def genEnd (exercise : String) : String := + s!" + +def main : IO UInt32 := do + runTestSuitesWithExitCode [{exercise.decapitalize}Tests] +" + +end DominoesGenerator diff --git a/generators/Generator/Generator/EtlGenerator.lean b/generators/Generator/Generator/EtlGenerator.lean index 8125663..9e5884b 100644 --- a/generators/Generator/Generator/EtlGenerator.lean +++ b/generators/Generator/Generator/EtlGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/ForthGenerator.lean b/generators/Generator/Generator/ForthGenerator.lean index b9ca64d..5d0d487 100644 --- a/generators/Generator/Generator/ForthGenerator.lean +++ b/generators/Generator/Generator/ForthGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/GameOfLifeGenerator.lean b/generators/Generator/Generator/GameOfLifeGenerator.lean index e61e8b4..645bc72 100644 --- a/generators/Generator/Generator/GameOfLifeGenerator.lean +++ b/generators/Generator/Generator/GameOfLifeGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/GigasecondGenerator.lean b/generators/Generator/Generator/GigasecondGenerator.lean index 3e15607..f19d9cb 100644 --- a/generators/Generator/Generator/GigasecondGenerator.lean +++ b/generators/Generator/Generator/GigasecondGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/GrainsGenerator.lean b/generators/Generator/Generator/GrainsGenerator.lean index f0cb86e..35479f8 100644 --- a/generators/Generator/Generator/GrainsGenerator.lean +++ b/generators/Generator/Generator/GrainsGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/GrepGenerator.lean b/generators/Generator/Generator/GrepGenerator.lean index e59130b..f781983 100644 --- a/generators/Generator/Generator/GrepGenerator.lean +++ b/generators/Generator/Generator/GrepGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/HighScoresGenerator.lean b/generators/Generator/Generator/HighScoresGenerator.lean index 88a39c1..eb93e39 100644 --- a/generators/Generator/Generator/HighScoresGenerator.lean +++ b/generators/Generator/Generator/HighScoresGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/HouseGenerator.lean b/generators/Generator/Generator/HouseGenerator.lean index 505edc8..965d36b 100644 --- a/generators/Generator/Generator/HouseGenerator.lean +++ b/generators/Generator/Generator/HouseGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper @@ -20,11 +20,7 @@ def genTestCase (exercise : String) (case : TreeMap.Raw String Json) : String := let input := case.get! "input" let startVerse := input.getObjValD "startVerse" |> (s!"⟨{·}, by decide⟩") let endVerse := input.getObjValD "endVerse" |> (s!"⟨{·}, by decide⟩") - let expected := case.get! "expected" - |>.getArr? - |> getOk - |>.map (λ ln => s!"{ln}") - |>.toList + let expected := serializeList (case.get! "expected") |> (s!"(String.intercalate \"\\n\\n\" {·})") let description := case.get! "description" |> (·.compress) diff --git a/generators/Generator/Generator/LeapGenerator.lean b/generators/Generator/Generator/LeapGenerator.lean index 1daeb83..2da61d9 100644 --- a/generators/Generator/Generator/LeapGenerator.lean +++ b/generators/Generator/Generator/LeapGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/PalindromeProductsGenerator.lean b/generators/Generator/Generator/PalindromeProductsGenerator.lean index 23e7de2..e25e730 100644 --- a/generators/Generator/Generator/PalindromeProductsGenerator.lean +++ b/generators/Generator/Generator/PalindromeProductsGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/ParallelLetterFrequencyGenerator.lean b/generators/Generator/Generator/ParallelLetterFrequencyGenerator.lean index e70a70e..0424838 100644 --- a/generators/Generator/Generator/ParallelLetterFrequencyGenerator.lean +++ b/generators/Generator/Generator/ParallelLetterFrequencyGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/PerfectNumbersGenerator.lean b/generators/Generator/Generator/PerfectNumbersGenerator.lean index 4824e51..441a29d 100644 --- a/generators/Generator/Generator/PerfectNumbersGenerator.lean +++ b/generators/Generator/Generator/PerfectNumbersGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/PhoneNumberGenerator.lean b/generators/Generator/Generator/PhoneNumberGenerator.lean index 6cf113d..25d2fdb 100644 --- a/generators/Generator/Generator/PhoneNumberGenerator.lean +++ b/generators/Generator/Generator/PhoneNumberGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/PrimeFactorsGenerator.lean b/generators/Generator/Generator/PrimeFactorsGenerator.lean index 921c26f..48e16bb 100644 --- a/generators/Generator/Generator/PrimeFactorsGenerator.lean +++ b/generators/Generator/Generator/PrimeFactorsGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/ProteinTranslationGenerator.lean b/generators/Generator/Generator/ProteinTranslationGenerator.lean index 50a2d8d..27f3317 100644 --- a/generators/Generator/Generator/ProteinTranslationGenerator.lean +++ b/generators/Generator/Generator/ProteinTranslationGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/PythagoreanTripletGenerator.lean b/generators/Generator/Generator/PythagoreanTripletGenerator.lean index feae701..e195a00 100644 --- a/generators/Generator/Generator/PythagoreanTripletGenerator.lean +++ b/generators/Generator/Generator/PythagoreanTripletGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/RailFenceCipherGenerator.lean b/generators/Generator/Generator/RailFenceCipherGenerator.lean index c2abd8e..5a6aa35 100644 --- a/generators/Generator/Generator/RailFenceCipherGenerator.lean +++ b/generators/Generator/Generator/RailFenceCipherGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/RationalNumbersGenerator.lean b/generators/Generator/Generator/RationalNumbersGenerator.lean index 76e9607..22cd542 100644 --- a/generators/Generator/Generator/RationalNumbersGenerator.lean +++ b/generators/Generator/Generator/RationalNumbersGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/RectanglesGenerator.lean b/generators/Generator/Generator/RectanglesGenerator.lean index 1053d5d..7231440 100644 --- a/generators/Generator/Generator/RectanglesGenerator.lean +++ b/generators/Generator/Generator/RectanglesGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/RelativeDistanceGenerator.lean b/generators/Generator/Generator/RelativeDistanceGenerator.lean index 737d25a..ace853f 100644 --- a/generators/Generator/Generator/RelativeDistanceGenerator.lean +++ b/generators/Generator/Generator/RelativeDistanceGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper @@ -16,6 +16,9 @@ open LeanTest def {exercise.decapitalize}Tests : TestSuite := (TestSuite.empty \"{exercise}\")" +def serializer (key : String) (value : Json) : String := + s!"(\"{key}\", {value})" + def genTestCase (exercise : String) (case : TreeMap.Raw String Json) : String := let input := case.get! "input" let expected := match case.get! "expected" |>.getNat? with @@ -23,10 +26,8 @@ def genTestCase (exercise : String) (case : TreeMap.Raw String Json) : String := | .ok x => some x let description := case.get! "description" |> (·.compress) - let inputKeyVals := getKeyValues (input.getObjValD "familyTree") - |>.eraseP (λ (k, _) => k == "playerA") - |>.eraseP (λ (k, _) => k == "playerB") - |>.map (λ (k, v) => (s!"\"{k}\"", v)) + let inputKeyVals := serializeObjectAsList (input.getObjValD "familyTree") serializer + let funName := getFunName (case.get! "property") let call := s!"({exercise}.{funName} {inputKeyVals} {input.getObjValD "personA"} {input.getObjValD "personB"})" s!" diff --git a/generators/Generator/Generator/RomanNumeralsGenerator.lean b/generators/Generator/Generator/RomanNumeralsGenerator.lean index ba9300a..e9b57bc 100644 --- a/generators/Generator/Generator/RomanNumeralsGenerator.lean +++ b/generators/Generator/Generator/RomanNumeralsGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/SayGenerator.lean b/generators/Generator/Generator/SayGenerator.lean index 9b88e01..738e819 100644 --- a/generators/Generator/Generator/SayGenerator.lean +++ b/generators/Generator/Generator/SayGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/SecretHandshakeGenerator.lean b/generators/Generator/Generator/SecretHandshakeGenerator.lean index 629dfed..ceecbae 100644 --- a/generators/Generator/Generator/SecretHandshakeGenerator.lean +++ b/generators/Generator/Generator/SecretHandshakeGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/SeriesGenerator.lean b/generators/Generator/Generator/SeriesGenerator.lean index 994d239..ef37906 100644 --- a/generators/Generator/Generator/SeriesGenerator.lean +++ b/generators/Generator/Generator/SeriesGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/SpaceAgeGenerator.lean b/generators/Generator/Generator/SpaceAgeGenerator.lean index f174e24..c104b41 100644 --- a/generators/Generator/Generator/SpaceAgeGenerator.lean +++ b/generators/Generator/Generator/SpaceAgeGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/SublistGenerator.lean b/generators/Generator/Generator/SublistGenerator.lean index e7c75f4..0b90a5e 100644 --- a/generators/Generator/Generator/SublistGenerator.lean +++ b/generators/Generator/Generator/SublistGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/TransposeGenerator.lean b/generators/Generator/Generator/TransposeGenerator.lean index 676fcc2..9588be3 100644 --- a/generators/Generator/Generator/TransposeGenerator.lean +++ b/generators/Generator/Generator/TransposeGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/TriangleGenerator.lean b/generators/Generator/Generator/TriangleGenerator.lean index 244fd6f..12ca530 100644 --- a/generators/Generator/Generator/TriangleGenerator.lean +++ b/generators/Generator/Generator/TriangleGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std open Lean diff --git a/generators/Generator/Generator/TwoBucketGenerator.lean b/generators/Generator/Generator/TwoBucketGenerator.lean index 9da2b80..2171730 100644 --- a/generators/Generator/Generator/TwoBucketGenerator.lean +++ b/generators/Generator/Generator/TwoBucketGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/WordyGenerator.lean b/generators/Generator/Generator/WordyGenerator.lean index afdb07c..cdc82b1 100644 --- a/generators/Generator/Generator/WordyGenerator.lean +++ b/generators/Generator/Generator/WordyGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Generator/YachtGenerator.lean b/generators/Generator/Generator/YachtGenerator.lean index 8729d91..14eedb4 100644 --- a/generators/Generator/Generator/YachtGenerator.lean +++ b/generators/Generator/Generator/YachtGenerator.lean @@ -1,4 +1,4 @@ -import Lean +import Lean.Data.Json import Std import Helper diff --git a/generators/Generator/Helper.lean b/generators/Generator/Helper.lean index 8e25090..e1979e9 100644 --- a/generators/Generator/Helper.lean +++ b/generators/Generator/Helper.lean @@ -1,5 +1,5 @@ import Std -import Lean +import Lean.Data.Json open Std open Lean @@ -13,6 +13,8 @@ s!"instance \{α β} [BEq α] [BEq β] : BEq (Except α β) where | .error e1, .error e2 => e1 == e2 | _, _ => false" +def indent : String := " " + def toCamel (string : String) : String := (string.splitOn " ").map String.capitalize |> String.join @@ -46,15 +48,7 @@ def exceptToString {α β} [ToString α] [ToString β] (except : Except α β) : | .error msg => s!"(.error {msg})" def getKeyValues (json : Json) : List (String × String) := - let map := getOk json.getObj? - let list := map.toList - let string := json.compress - let sorted := list.mergeSort (fun (k1, _) (k2, _) => - let pos1 := string.toSlice.find? k1 |> (Option.get! ·) - let pos2 := string.toSlice.find? k2 |> (Option.get! ·) - pos1 < pos2 - ) - sorted.map (fun (k, v) => (k, v.compress)) + getOk json.getObj? |>.toList |>.map (λ (a, b) => (a, b.compress)) def insertAllInputs (input : Json) : String := let values := getKeyValues input @@ -69,4 +63,36 @@ def getFunName (property : Json) : String := def toStruct (string : String) : String := string.replace "[" "⟨" |> (·.replace "]" "⟩") +def serializeContent + (json : Json) + (serializer : Json → String) + : List String := + json.getArr? + |> getOk + |>.map serializer + |>.toList + +def serializeList + (json : Json) + (serializer : Json → String := fun j => s!"{j}") + (separator : String := s!",\n{indent} ") + : String := + let contents := serializeContent json serializer + match contents with + | [] => "[]" + | xs => + let joined := String.intercalate separator xs + s!"[\n{indent} {joined}\n{indent}]" + +def serializeObjectAsList + (json : Json) + (serializer : String → Json → String := fun k v => s!"[{k}, {v}]") + (separator : String := s!",\n{indent} ") + : String := + let joined := getOk json.getObj? + |>.toList + |>.map (Function.uncurry serializer) + |> String.intercalate separator + s!"[\n{indent} {joined}\n{indent}]" + end Helper