trackler 2.2.1.107 → 2.2.1.108
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/pig-latin/description.md +4 -4
- data/tracks/c/config.json +42 -0
- data/tracks/c/exercises/bracket-push/README.md +3 -0
- data/tracks/c/exercises/bracket-push/makefile +25 -0
- data/tracks/c/exercises/bracket-push/src/example.c +52 -0
- data/tracks/c/exercises/bracket-push/src/example.h +7 -0
- data/tracks/c/exercises/bracket-push/test/test_bracket_push.c +132 -0
- data/tracks/c/exercises/bracket-push/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/bracket-push/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/bracket-push/test/vendor/unity_internals.h +701 -0
- data/tracks/c/exercises/etl/README.md +46 -0
- data/tracks/c/exercises/etl/makefile +25 -0
- data/tracks/c/exercises/etl/src/example.c +44 -0
- data/tracks/c/exercises/etl/src/example.h +18 -0
- data/tracks/c/exercises/etl/test/test_etl.c +120 -0
- data/tracks/c/exercises/etl/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/etl/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/etl/test/vendor/unity_internals.h +701 -0
- data/tracks/c/exercises/luhn/README.md +64 -0
- data/tracks/c/exercises/luhn/makefile +25 -0
- data/tracks/c/exercises/luhn/src/example.c +38 -0
- data/tracks/c/exercises/luhn/src/example.h +7 -0
- data/tracks/c/exercises/luhn/test/test_luhn.c +109 -0
- data/tracks/c/exercises/luhn/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/luhn/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/luhn/test/vendor/unity_internals.h +701 -0
- data/tracks/c/exercises/prime-factors/README.md +29 -0
- data/tracks/c/exercises/prime-factors/makefile +25 -0
- data/tracks/c/exercises/prime-factors/src/example.c +28 -0
- data/tracks/c/exercises/prime-factors/src/example.h +11 -0
- data/tracks/c/exercises/prime-factors/test/test_prime_factors.c +96 -0
- data/tracks/c/exercises/prime-factors/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/prime-factors/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/prime-factors/test/vendor/unity_internals.h +701 -0
- data/tracks/clojure/exercises/hello-world/src/example.clj +2 -3
- data/tracks/clojure/exercises/hello-world/test/hello_world_test.clj +0 -6
- data/tracks/common-lisp/README.md +3 -8
- data/tracks/common-lisp/config/exercise_readme.go.tmpl +1 -1
- data/tracks/common-lisp/exercises/acronym/README.md +1 -1
- data/tracks/common-lisp/exercises/acronym/acronym-test.lisp +0 -5
- data/tracks/common-lisp/exercises/allergies/README.md +1 -1
- data/tracks/common-lisp/exercises/anagram/README.md +1 -1
- data/tracks/common-lisp/exercises/atbash-cipher/README.md +1 -1
- data/tracks/common-lisp/exercises/beer-song/README.md +1 -1
- data/tracks/common-lisp/exercises/binary/README.md +1 -1
- data/tracks/common-lisp/exercises/bob/README.md +1 -1
- data/tracks/common-lisp/exercises/collatz-conjecture/README.md +1 -1
- data/tracks/common-lisp/exercises/crypto-square/README.md +1 -1
- data/tracks/common-lisp/exercises/difference-of-squares/README.md +1 -1
- data/tracks/common-lisp/exercises/etl/README.md +1 -1
- data/tracks/common-lisp/exercises/gigasecond/README.md +1 -1
- data/tracks/common-lisp/exercises/grade-school/README.md +1 -1
- data/tracks/common-lisp/exercises/grains/README.md +1 -1
- data/tracks/common-lisp/exercises/hamming/README.md +1 -1
- data/tracks/common-lisp/exercises/hello-world/README.md +1 -1
- data/tracks/common-lisp/exercises/isogram/README.md +1 -1
- data/tracks/common-lisp/exercises/leap/README.md +1 -1
- data/tracks/common-lisp/exercises/meetup/README.md +1 -1
- data/tracks/common-lisp/exercises/nucleotide-count/README.md +1 -1
- data/tracks/common-lisp/exercises/pascals-triangle/README.md +1 -1
- data/tracks/common-lisp/exercises/perfect-numbers/README.md +1 -1
- data/tracks/common-lisp/exercises/phone-number/README.md +1 -1
- data/tracks/common-lisp/exercises/prime-factors/README.md +1 -1
- data/tracks/common-lisp/exercises/raindrops/README.md +1 -1
- data/tracks/common-lisp/exercises/rna-transcription/README.md +1 -1
- data/tracks/common-lisp/exercises/robot-name/README.md +1 -1
- data/tracks/common-lisp/exercises/roman-numerals/README.md +1 -1
- data/tracks/common-lisp/exercises/scrabble-score/README.md +1 -1
- data/tracks/common-lisp/exercises/sieve/README.md +1 -1
- data/tracks/common-lisp/exercises/space-age/README.md +1 -1
- data/tracks/common-lisp/exercises/strain/README.md +1 -1
- data/tracks/common-lisp/exercises/sublist/README.md +1 -1
- data/tracks/common-lisp/exercises/triangle/README.md +1 -1
- data/tracks/common-lisp/exercises/trinary/README.md +1 -1
- data/tracks/common-lisp/exercises/word-count/README.md +1 -1
- data/tracks/csharp/exercises/meetup/MeetupTest.cs +177 -177
- data/tracks/csharp/exercises/robot-simulator/Example.cs +27 -27
- data/tracks/csharp/exercises/robot-simulator/RobotSimulator.cs +3 -3
- data/tracks/csharp/exercises/robot-simulator/RobotSimulatorTest.cs +152 -31
- data/tracks/csharp/generators/Exercises/Meetup.cs +8 -9
- data/tracks/csharp/generators/Exercises/RobotSimulator.cs +116 -0
- data/tracks/delphi/exercises/allergies/uAllergyTests.pas +28 -0
- data/tracks/delphi/exercises/binary-search/uBinarySearchExample.pas +6 -0
- data/tracks/delphi/exercises/binary-search/uBinarySearchTest.pas +53 -37
- data/tracks/delphi/exercises/collatz-conjecture/uCollatzconjectureTest.pas +3 -0
- data/tracks/delphi/exercises/etl/uETLtests.pas +13 -10
- data/tracks/delphi/exercises/grains/uGrainsTests.pas +5 -2
- data/tracks/delphi/exercises/hamming/uHammingTests.pas +3 -0
- data/tracks/delphi/exercises/hello-world/uTestHelloWorld.pas +3 -0
- data/tracks/delphi/exercises/leap/uLeapTests.pas +3 -0
- data/tracks/delphi/exercises/minesweeper/uMineSweeperTest.pas +3 -0
- data/tracks/delphi/exercises/nucleotide-count/uNucleotideCountTest.pas +5 -17
- data/tracks/delphi/exercises/perfect-numbers/uPerfectNumbersExample.pas +6 -0
- data/tracks/delphi/exercises/perfect-numbers/uPerfectNumbersTest.pas +77 -26
- data/tracks/delphi/exercises/pig-latin/README.md +4 -4
- data/tracks/delphi/exercises/pig-latin/uTestPigLatin.pas +12 -9
- data/tracks/delphi/exercises/poker/uPokerExample.pas +81 -26
- data/tracks/delphi/exercises/poker/uPokerTest.pas +343 -121
- data/tracks/delphi/exercises/raindrops/uRaindropsTest.pas +3 -0
- data/tracks/delphi/exercises/saddle-points/uSaddlePointsExample.pas +4 -3
- data/tracks/delphi/exercises/saddle-points/uSaddlePointsTests.pas +25 -47
- data/tracks/delphi/exercises/triangle/uTestTriangle.pas +4 -2
- data/tracks/delphi/exercises/two-fer/utwoferTest.pas +3 -0
- data/tracks/delphi/exercises/wordy/uWordyTests.pas +3 -0
- data/tracks/ecmascript/.travis.yml +2 -1
- data/tracks/ecmascript/config.json +14 -0
- data/tracks/ecmascript/exercises/accumulate/package.json +1 -2
- data/tracks/ecmascript/exercises/acronym/package.json +1 -2
- data/tracks/ecmascript/exercises/all-your-base/package.json +1 -2
- data/tracks/ecmascript/exercises/allergies/package.json +1 -2
- data/tracks/ecmascript/exercises/alphametics/package.json +1 -2
- data/tracks/ecmascript/exercises/anagram/package.json +1 -2
- data/tracks/ecmascript/exercises/atbash-cipher/package.json +1 -2
- data/tracks/ecmascript/exercises/beer-song/package.json +1 -2
- data/tracks/ecmascript/exercises/binary-search-tree/package.json +1 -2
- data/tracks/ecmascript/exercises/binary-search/package.json +1 -2
- data/tracks/ecmascript/exercises/binary/package.json +1 -2
- data/tracks/ecmascript/exercises/bob/README.md +2 -0
- data/tracks/ecmascript/exercises/bob/bob.spec.js +5 -5
- data/tracks/ecmascript/exercises/bob/example.js +7 -2
- data/tracks/ecmascript/exercises/bob/package.json +1 -2
- data/tracks/ecmascript/exercises/bowling/package.json +1 -2
- data/tracks/ecmascript/exercises/bracket-push/package.json +1 -2
- data/tracks/ecmascript/exercises/change/package.json +1 -2
- data/tracks/ecmascript/exercises/circular-buffer/package.json +1 -2
- data/tracks/ecmascript/exercises/clock/package.json +1 -2
- data/tracks/ecmascript/exercises/collatz-conjecture/package.json +1 -2
- data/tracks/ecmascript/exercises/complex-numbers/package.json +1 -2
- data/tracks/ecmascript/exercises/connect/package.json +1 -2
- data/tracks/ecmascript/exercises/crypto-square/package.json +1 -2
- data/tracks/ecmascript/exercises/custom-set/package.json +1 -2
- data/tracks/ecmascript/exercises/diamond/package.json +1 -2
- data/tracks/ecmascript/exercises/difference-of-squares/package.json +1 -2
- data/tracks/ecmascript/exercises/diffie-hellman/package.json +1 -2
- data/tracks/ecmascript/exercises/etl/package.json +1 -2
- data/tracks/ecmascript/exercises/flatten-array/package.json +1 -2
- data/tracks/ecmascript/exercises/food-chain/package.json +1 -2
- data/tracks/ecmascript/exercises/gigasecond/package.json +1 -2
- data/tracks/ecmascript/exercises/grade-school/package.json +1 -2
- data/tracks/ecmascript/exercises/grains/package.json +1 -2
- data/tracks/ecmascript/exercises/hamming/package.json +1 -2
- data/tracks/ecmascript/exercises/hello-world/package.json +1 -2
- data/tracks/ecmascript/exercises/hexadecimal/package.json +1 -2
- data/tracks/ecmascript/exercises/house/package.json +1 -2
- data/tracks/ecmascript/exercises/isbn-verifier/package.json +1 -2
- data/tracks/ecmascript/exercises/isogram/package.json +1 -2
- data/tracks/ecmascript/exercises/kindergarten-garden/package.json +1 -2
- data/tracks/ecmascript/exercises/largest-series-product/package.json +1 -2
- data/tracks/ecmascript/exercises/leap/package.json +1 -2
- data/tracks/ecmascript/exercises/linked-list/package.json +1 -2
- data/tracks/ecmascript/exercises/list-ops/package.json +1 -2
- data/tracks/ecmascript/exercises/luhn/package.json +1 -2
- data/tracks/ecmascript/exercises/matrix/package.json +1 -2
- data/tracks/ecmascript/exercises/meetup/package.json +1 -2
- data/tracks/ecmascript/exercises/minesweeper/package.json +1 -2
- data/tracks/ecmascript/exercises/nth-prime/package.json +1 -2
- data/tracks/ecmascript/exercises/nucleotide-count/README.md +60 -0
- data/tracks/ecmascript/exercises/nucleotide-count/example.js +13 -0
- data/tracks/ecmascript/exercises/nucleotide-count/nucleotide-count.spec.js +23 -0
- data/tracks/ecmascript/exercises/nucleotide-count/package.json +70 -0
- data/tracks/ecmascript/exercises/ocr-numbers/package.json +1 -2
- data/tracks/ecmascript/exercises/octal/package.json +1 -2
- data/tracks/ecmascript/exercises/palindrome-products/package.json +1 -2
- data/tracks/ecmascript/exercises/pangram/package.json +1 -2
- data/tracks/ecmascript/exercises/pascals-triangle/package.json +1 -2
- data/tracks/ecmascript/exercises/perfect-numbers/package.json +1 -2
- data/tracks/ecmascript/exercises/phone-number/package.json +1 -2
- data/tracks/ecmascript/exercises/pig-latin/package.json +1 -2
- data/tracks/ecmascript/exercises/prime-factors/package.json +1 -2
- data/tracks/ecmascript/exercises/protein-translation/package.json +1 -2
- data/tracks/ecmascript/exercises/proverb/package.json +1 -2
- data/tracks/ecmascript/exercises/pythagorean-triplet/package.json +1 -2
- data/tracks/ecmascript/exercises/queen-attack/package.json +1 -2
- data/tracks/ecmascript/exercises/raindrops/package.json +1 -2
- data/tracks/ecmascript/exercises/react/package.json +1 -2
- data/tracks/ecmascript/exercises/rectangles/package.json +1 -2
- data/tracks/ecmascript/exercises/rna-transcription/package.json +1 -2
- data/tracks/ecmascript/exercises/robot-name/package.json +1 -2
- data/tracks/ecmascript/exercises/robot-simulator/package.json +1 -2
- data/tracks/ecmascript/exercises/roman-numerals/package.json +1 -2
- data/tracks/ecmascript/exercises/rotational-cipher/package.json +1 -2
- data/tracks/ecmascript/exercises/run-length-encoding/package.json +1 -2
- data/tracks/ecmascript/exercises/saddle-points/package.json +1 -2
- data/tracks/ecmascript/exercises/say/package.json +1 -2
- data/tracks/ecmascript/exercises/scrabble-score/package.json +1 -2
- data/tracks/ecmascript/exercises/secret-handshake/package.json +1 -2
- data/tracks/ecmascript/exercises/series/package.json +1 -2
- data/tracks/ecmascript/exercises/sieve/package.json +1 -2
- data/tracks/ecmascript/exercises/simple-cipher/package.json +1 -2
- data/tracks/ecmascript/exercises/simple-linked-list/package.json +1 -2
- data/tracks/ecmascript/exercises/space-age/package.json +1 -2
- data/tracks/ecmascript/exercises/spiral-matrix/package.json +1 -2
- data/tracks/ecmascript/exercises/strain/package.json +1 -2
- data/tracks/ecmascript/exercises/sublist/package.json +1 -2
- data/tracks/ecmascript/exercises/sum-of-multiples/package.json +1 -2
- data/tracks/ecmascript/exercises/transpose/package.json +1 -2
- data/tracks/ecmascript/exercises/triangle/package.json +1 -2
- data/tracks/ecmascript/exercises/trinary/package.json +1 -2
- data/tracks/ecmascript/exercises/twelve-days/package.json +1 -2
- data/tracks/ecmascript/exercises/two-bucket/package.json +1 -2
- data/tracks/ecmascript/exercises/two-fer/package.json +1 -2
- data/tracks/ecmascript/exercises/word-count/package.json +1 -2
- data/tracks/ecmascript/exercises/word-search/package.json +1 -2
- data/tracks/ecmascript/exercises/wordy/package.json +1 -2
- data/tracks/ecmascript/package.json +1 -2
- data/tracks/elm/config.json +13 -1
- data/tracks/elm/exercises/binary-search/BinarySearch.elm +9 -0
- data/tracks/elm/exercises/binary-search/BinarySearch.example.elm +36 -0
- data/tracks/elm/exercises/binary-search/README.md +71 -0
- data/tracks/elm/exercises/binary-search/elm-package.json +15 -0
- data/tracks/elm/exercises/binary-search/tests/Tests.elm +66 -0
- data/tracks/elm/exercises/binary-search/tests/elm-package.json +17 -0
- data/tracks/elm/exercises/hamming/Hamming.example.elm +3 -3
- data/tracks/elm/exercises/hamming/tests/Tests.elm +14 -14
- data/tracks/go/exercises/word-search/.meta/gen.go +9 -7
- data/tracks/go/exercises/word-search/cases_test.go +2 -2
- data/tracks/groovy/config.json +12 -0
- data/tracks/groovy/exercises/bank-account/BankAccount.groovy +30 -0
- data/tracks/groovy/exercises/bank-account/BankAccountSpec.groovy +200 -0
- data/tracks/groovy/exercises/bank-account/Example.groovy +47 -0
- data/tracks/groovy/exercises/bank-account/README.md +75 -0
- data/tracks/groovy/exercises/phone-number/Example.groovy +10 -14
- data/tracks/groovy/exercises/phone-number/PhoneNumber.groovy +2 -14
- data/tracks/groovy/exercises/phone-number/PhoneNumberSpec.groovy +39 -26
- data/tracks/groovy/exercises/phone-number/README.md +1 -1
- data/tracks/java/config.json +13 -0
- data/tracks/java/exercises/forth/README.md +10 -0
- data/tracks/java/exercises/rna-transcription/.meta/version +1 -1
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/java/exercises/sieve/.meta/version +1 -1
- data/tracks/java/exercises/spiral-matrix/.meta/version +1 -1
- data/tracks/java/exercises/triangle/.meta/version +1 -1
- data/tracks/java/exercises/two-bucket/README.md +1 -1
- data/tracks/java/exercises/zipper/.meta/src/reference/java/Zipper.java +199 -0
- data/tracks/java/exercises/zipper/.meta/version +1 -0
- data/tracks/java/exercises/zipper/README.md +42 -0
- data/tracks/java/exercises/zipper/build.gradle +18 -0
- data/tracks/java/exercises/zipper/src/main/java/.keep +0 -0
- data/tracks/java/exercises/zipper/src/test/java/ZipperTest.java +204 -0
- data/tracks/javascript/package.json +10 -0
- data/tracks/ocaml/.travis-ci.sh +1 -1
- data/tracks/ocaml/.travis.yml +1 -1
- data/tracks/ocaml/README.md +1 -1
- data/tracks/ocaml/config/exercise_readme.go.tmpl +2 -0
- data/tracks/python/config.json +13 -0
- data/tracks/python/exercises/all-your-base/all_your_base.py +1 -1
- data/tracks/python/exercises/all-your-base/all_your_base_test.py +8 -8
- data/tracks/python/exercises/alphametics/alphametics_test.py +49 -9
- data/tracks/python/exercises/binary-search-tree/binary_search_tree.py +11 -5
- data/tracks/python/exercises/binary-search-tree/binary_search_tree_test.py +89 -48
- data/tracks/python/exercises/binary-search-tree/example.py +42 -52
- data/tracks/python/exercises/binary-search/binary_search_test.py +1 -1
- data/tracks/python/exercises/book-store/book_store_test.py +18 -39
- data/tracks/python/exercises/book-store/example.py +1 -1
- data/tracks/python/exercises/bowling/bowling.py +0 -2
- data/tracks/python/exercises/bowling/bowling_test.py +49 -13
- data/tracks/python/exercises/bowling/example.py +85 -135
- data/tracks/python/exercises/bracket-push/bracket_push.py +1 -1
- data/tracks/python/exercises/bracket-push/bracket_push_test.py +16 -16
- data/tracks/python/exercises/bracket-push/example.py +2 -2
- data/tracks/python/exercises/change/change_test.py +17 -4
- data/tracks/python/exercises/change/example.py +2 -2
- data/tracks/python/exercises/circular-buffer/circular_buffer.py +12 -0
- data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +4 -11
- data/tracks/python/exercises/clock/clock.py +10 -1
- data/tracks/python/exercises/clock/clock_test.py +9 -9
- data/tracks/python/exercises/clock/example.py +4 -1
- data/tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py +15 -5
- data/tracks/python/exercises/collatz-conjecture/example.py +1 -1
- data/tracks/python/exercises/complex-numbers/complex_numbers_test.py +37 -26
- data/tracks/python/exercises/custom-set/custom_set_test.py +1 -1
- data/tracks/python/exercises/diamond/diamond_test.py +1 -1
- data/tracks/python/exercises/dominoes/dominoes_test.py +1 -1
- data/tracks/python/exercises/forth/forth_test.py +1 -1
- data/tracks/python/exercises/house/example.py +11 -3
- data/tracks/python/exercises/house/house.py +1 -5
- data/tracks/python/exercises/house/house_test.py +269 -116
- data/tracks/python/exercises/list-ops/list_ops_test.py +1 -1
- data/tracks/python/exercises/luhn/luhn.py +3 -0
- data/tracks/python/exercises/luhn/luhn_test.py +1 -1
- data/tracks/python/exercises/markdown/markdown_test.py +2 -3
- data/tracks/python/exercises/minesweeper/minesweeper_test.py +1 -1
- data/tracks/python/exercises/nth-prime/nth_prime_test.py +1 -1
- data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +1 -1
- data/tracks/python/exercises/palindrome-products/palindrome_products_test.py +14 -6
- data/tracks/python/exercises/perfect-numbers/perfect_numbers_test.py +1 -24
- data/tracks/python/exercises/phone-number/phone_number_test.py +11 -3
- data/tracks/python/exercises/poker/example.py +4 -3
- data/tracks/python/exercises/poker/poker.py +1 -1
- data/tracks/python/exercises/poker/poker_test.py +196 -119
- data/tracks/python/exercises/pov/example.py +3 -3
- data/tracks/python/exercises/pov/pov.py +2 -2
- data/tracks/python/exercises/pov/pov_test.py +19 -18
- data/tracks/python/exercises/protein-translation/protein_translation_test.py +14 -24
- data/tracks/python/exercises/rail-fence-cipher/rail_fence_cipher_test.py +1 -1
- data/tracks/python/exercises/rational-numbers/README.md +59 -0
- data/tracks/python/exercises/rational-numbers/example.py +58 -0
- data/tracks/python/exercises/rational-numbers/rational_numbers.py +34 -0
- data/tracks/python/exercises/rational-numbers/rational_numbers_test.py +132 -0
- data/tracks/python/exercises/rectangles/rectangles_test.py +1 -1
- data/tracks/python/exercises/roman-numerals/roman_numerals_test.py +2 -1
- data/tracks/python/exercises/run-length-encoding/run_length_encoding_test.py +2 -2
- data/tracks/python/exercises/saddle-points/saddle_points_test.py +18 -18
- data/tracks/python/exercises/scale-generator/example.py +4 -5
- data/tracks/python/exercises/scale-generator/scale_generator.py +2 -2
- data/tracks/python/exercises/scale-generator/scale_generator_test.py +38 -73
- data/tracks/python/exercises/secret-handshake/secret_handshake_test.py +1 -1
- data/tracks/python/exercises/tournament/tournament_test.py +1 -1
- data/tracks/python/exercises/twelve-days/example.py +3 -8
- data/tracks/python/exercises/twelve-days/twelve_days.py +1 -9
- data/tracks/python/exercises/twelve-days/twelve_days_test.py +51 -50
- data/tracks/python/exercises/two-bucket/example.py +3 -4
- data/tracks/python/exercises/two-bucket/two_bucket.py +1 -1
- data/tracks/python/exercises/two-bucket/two_bucket_test.py +8 -13
- data/tracks/python/exercises/two-fer/two_fer_test.py +8 -9
- data/tracks/python/exercises/variable-length-quantity/variable_length_quantity_test.py +1 -1
- data/tracks/python/exercises/word-count/word_count_test.py +8 -14
- data/tracks/python/exercises/word-search/word_search.py +3 -15
- data/tracks/python/exercises/word-search/word_search_test.py +1 -1
- data/tracks/python/exercises/wordy/wordy_test.py +1 -1
- data/tracks/python/exercises/zebra-puzzle/example.py +11 -2
- data/tracks/python/exercises/zebra-puzzle/zebra_puzzle.py +5 -1
- data/tracks/python/exercises/zebra-puzzle/zebra_puzzle_test.py +8 -5
- data/tracks/python/exercises/zipper/zipper_test.py +24 -30
- data/tracks/scala/exercises/dominoes/src/test/scala/DominoesTest.scala +2 -2
- data/tracks/scala/exercises/flatten-array/src/test/scala/FlattenArrayTest.scala +1 -1
- data/tracks/scala/exercises/food-chain/example.scala +3 -3
- data/tracks/scala/exercises/food-chain/src/test/scala/FoodChainTest.scala +12 -12
- data/tracks/scala/exercises/forth/src/test/scala/ForthTest.scala +35 -10
- data/tracks/scala/exercises/gigasecond/src/test/scala/GigasecondTest.scala +2 -2
- data/tracks/scala/exercises/hamming/src/test/scala/HammingTest.scala +4 -4
- data/tracks/scala/exercises/hello-world/src/test/scala/HelloWorldTest.scala +2 -3
- data/tracks/scala/exercises/house/example.scala +4 -5
- data/tracks/scala/exercises/house/src/test/scala/HouseTest.scala +16 -17
- data/tracks/scala/exercises/isogram/src/test/scala/IsogramTest.scala +3 -3
- data/tracks/scala/exercises/kindergarten-garden/src/test/scala/GardenTest.scala +1 -29
- data/tracks/scala/exercises/largest-series-product/src/test/scala/SeriesTest.scala +20 -17
- data/tracks/scala/exercises/leap/src/test/scala/LeapTest.scala +3 -3
- data/tracks/scala/exercises/luhn/src/test/scala/LuhnTest.scala +3 -3
- data/tracks/scala/exercises/matrix/example.scala +5 -1
- data/tracks/scala/exercises/matrix/src/test/scala/MatrixTest.scala +48 -12
- data/tracks/scala/exercises/meetup/src/test/scala/MeetupTest.scala +2 -1
- data/tracks/scala/exercises/minesweeper/src/test/scala/MinesweeperTest.scala +9 -9
- data/tracks/scala/testgen/src/main/scala/DominoesTestGenerator.scala +6 -6
- data/tracks/scala/testgen/src/main/scala/FlattenArrayTestGenerator.scala +6 -6
- data/tracks/scala/testgen/src/main/scala/FoodChainTestGenerator.scala +10 -12
- data/tracks/scala/testgen/src/main/scala/ForthTestGenerator.scala +6 -6
- data/tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala +6 -4
- data/tracks/scala/testgen/src/main/scala/HammingTestGenerator.scala +3 -3
- data/tracks/scala/testgen/src/main/scala/HouseTestGenerator.scala +10 -16
- data/tracks/scala/testgen/src/main/scala/IsogramTestGenerator.scala +1 -1
- data/tracks/scala/testgen/src/main/scala/KindergartenGardenTestGenerator.scala +6 -5
- data/tracks/scala/testgen/src/main/scala/LeapTestGenerator.scala +3 -3
- data/tracks/scala/testgen/src/main/scala/LuhnTestGenerator.scala +1 -1
- data/tracks/scala/testgen/src/main/scala/MatrixTestGenerator.scala +35 -0
- data/tracks/scala/testgen/src/main/scala/MeetupTestGenerator.scala +14 -11
- data/tracks/scala/testgen/src/main/scala/MinesweeperTestGenerator.scala +1 -1
- data/tracks/scala/testgen/src/main/scala/SeriesTestGenerator.scala +3 -3
- data/tracks/typescript/config/exercise_readme.go.tmpl +25 -4
- data/tracks/typescript/exercises/acronym/README.md +7 -2
- data/tracks/typescript/exercises/atbash-cipher/README.md +2 -1
- data/tracks/typescript/exercises/beer-song/README.md +2 -2
- data/tracks/typescript/exercises/binary-search-tree/README.md +2 -0
- data/tracks/typescript/exercises/circular-buffer/README.md +16 -7
- data/tracks/typescript/exercises/clock/README.md +6 -0
- data/tracks/typescript/exercises/diamond/README.md +8 -7
- data/tracks/typescript/exercises/etl/README.md +3 -1
- data/tracks/typescript/exercises/food-chain/README.md +1 -1
- data/tracks/typescript/exercises/grade-school/README.md +0 -1
- data/tracks/typescript/exercises/hello-world/.meta/hints.md +378 -0
- data/tracks/typescript/exercises/hello-world/README.md +37 -11
- data/tracks/typescript/exercises/largest-series-product/README.md +1 -6
- data/tracks/typescript/exercises/leap/README.md +1 -1
- data/tracks/typescript/exercises/linked-list/README.md +20 -15
- data/tracks/typescript/exercises/nth-prime/README.md +7 -2
- data/tracks/typescript/exercises/ocr-numbers/README.md +7 -6
- data/tracks/typescript/exercises/pangram/README.md +1 -1
- data/tracks/typescript/exercises/pascals-triangle/README.md +1 -1
- data/tracks/typescript/exercises/phone-number/README.md +4 -3
- data/tracks/typescript/exercises/prime-factors/README.md +1 -12
- data/tracks/typescript/exercises/pythagorean-triplet/README.md +3 -7
- data/tracks/typescript/exercises/rna-transcription/README.md +2 -2
- data/tracks/typescript/exercises/robot-simulator/README.md +3 -1
- data/tracks/typescript/exercises/scrabble-score/README.md +3 -1
- data/tracks/typescript/exercises/series/README.md +0 -4
- data/tracks/typescript/exercises/space-age/README.md +1 -1
- data/tracks/typescript/exercises/strain/README.md +6 -0
- data/tracks/typescript/exercises/sum-of-multiples/README.md +4 -7
- data/tracks/typescript/exercises/two-bucket/README.md +15 -19
- data/tracks/typescript/exercises/word-count/README.md +1 -2
- data/tracks/typescript/exercises/wordy/README.md +0 -5
- metadata +61 -5
- data/tracks/common-lisp/exercises/bob/.meta/description.md +0 -10
- data/tracks/javascript/.eslintrc.json +0 -10
- data/tracks/typescript/docs/EXERCISE_README_INSERT.md +0 -24
@@ -41,7 +41,7 @@ class Tree(object):
|
|
41
41
|
tree.children.append(child.remove(node))
|
42
42
|
return tree
|
43
43
|
|
44
|
-
def
|
44
|
+
def from_pov(self, from_node):
|
45
45
|
stack = [self]
|
46
46
|
visited = set()
|
47
47
|
while stack:
|
@@ -55,8 +55,8 @@ class Tree(object):
|
|
55
55
|
stack.append(child.add(tree.remove(child.label)))
|
56
56
|
raise ValueError("Tree could not be reoriented")
|
57
57
|
|
58
|
-
def
|
59
|
-
reordered = self.
|
58
|
+
def path_to(self, from_node, to_node):
|
59
|
+
reordered = self.from_pov(from_node)
|
60
60
|
stack = reordered.children
|
61
61
|
path = [from_node]
|
62
62
|
while path[-1] != to_node:
|
@@ -18,8 +18,8 @@ class Tree(object):
|
|
18
18
|
def __eq__(self, other):
|
19
19
|
return self.__dict__() == other.__dict__()
|
20
20
|
|
21
|
-
def
|
21
|
+
def from_pov(self, from_node):
|
22
22
|
pass
|
23
23
|
|
24
|
-
def
|
24
|
+
def path_to(self, from_node, to_node):
|
25
25
|
pass
|
@@ -3,16 +3,13 @@ import unittest
|
|
3
3
|
from pov import Tree
|
4
4
|
|
5
5
|
|
6
|
-
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.
|
6
|
+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
|
7
7
|
|
8
8
|
class PovTest(unittest.TestCase):
|
9
|
-
def assertTreeEquals(self, result, expected):
|
10
|
-
self.assertEqual(result, expected,
|
11
|
-
'{} != {}'.format(result, expected))
|
12
9
|
|
13
10
|
def test_singleton_returns_same_tree(self):
|
14
11
|
tree = Tree('x')
|
15
|
-
self.assertTreeEquals(tree.
|
12
|
+
self.assertTreeEquals(tree.from_pov('x'), tree)
|
16
13
|
|
17
14
|
def test_can_reroot_tree_with_parent_and_one_sibling(self):
|
18
15
|
tree = Tree('parent', [
|
@@ -24,7 +21,7 @@ class PovTest(unittest.TestCase):
|
|
24
21
|
Tree('sibling')
|
25
22
|
])
|
26
23
|
])
|
27
|
-
self.assertTreeEquals(tree.
|
24
|
+
self.assertTreeEquals(tree.from_pov('x'), expected)
|
28
25
|
|
29
26
|
def test_can_reroot_tree_with_parent_and_many_siblings(self):
|
30
27
|
tree = Tree('parent', [
|
@@ -40,7 +37,7 @@ class PovTest(unittest.TestCase):
|
|
40
37
|
Tree('c')
|
41
38
|
])
|
42
39
|
])
|
43
|
-
self.assertTreeEquals(tree.
|
40
|
+
self.assertTreeEquals(tree.from_pov('x'), expected)
|
44
41
|
|
45
42
|
def test_can_reroot_a_tree_with_new_root_deeply_nested(self):
|
46
43
|
tree = Tree('level-0', [
|
@@ -61,7 +58,7 @@ class PovTest(unittest.TestCase):
|
|
61
58
|
])
|
62
59
|
])
|
63
60
|
])
|
64
|
-
self.assertTreeEquals(tree.
|
61
|
+
self.assertTreeEquals(tree.from_pov('x'), expected)
|
65
62
|
|
66
63
|
def test_moves_children_of_new_root_to_same_level_as_former_parent(self):
|
67
64
|
tree = Tree('parent', [
|
@@ -75,7 +72,7 @@ class PovTest(unittest.TestCase):
|
|
75
72
|
Tree('kid-0'),
|
76
73
|
Tree('kid-1')
|
77
74
|
])
|
78
|
-
self.assertTreeEquals(tree.
|
75
|
+
self.assertTreeEquals(tree.from_pov('x'), expected)
|
79
76
|
|
80
77
|
def test_can_reroot_complex_tree_with_cousins(self):
|
81
78
|
tree = Tree('grandparent', [
|
@@ -106,12 +103,12 @@ class PovTest(unittest.TestCase):
|
|
106
103
|
])
|
107
104
|
])
|
108
105
|
])
|
109
|
-
self.assertTreeEquals(tree.
|
106
|
+
self.assertTreeEquals(tree.from_pov('x'), expected)
|
110
107
|
|
111
108
|
def test_errors_if_target_does_not_exist_in_singleton_tree(self):
|
112
109
|
tree = Tree('x')
|
113
110
|
with self.assertRaisesWithMessage(ValueError):
|
114
|
-
tree.
|
111
|
+
tree.from_pov('nonexistent')
|
115
112
|
|
116
113
|
def test_errors_if_target_does_not_exist_in_large_tree(self):
|
117
114
|
tree = Tree('parent', [
|
@@ -123,7 +120,7 @@ class PovTest(unittest.TestCase):
|
|
123
120
|
Tree('sibling-1')
|
124
121
|
])
|
125
122
|
with self.assertRaisesWithMessage(ValueError):
|
126
|
-
tree.
|
123
|
+
tree.from_pov('nonexistent')
|
127
124
|
|
128
125
|
def test_find_path_between_two_nodes(self):
|
129
126
|
tree = Tree('parent', [
|
@@ -131,7 +128,7 @@ class PovTest(unittest.TestCase):
|
|
131
128
|
Tree('sibling')
|
132
129
|
])
|
133
130
|
expected = ['x', 'parent']
|
134
|
-
self.assertEqual(tree.
|
131
|
+
self.assertEqual(tree.path_to('x', 'parent'), expected)
|
135
132
|
|
136
133
|
def test_can_find_path_to_sibling(self):
|
137
134
|
tree = Tree('parent', [
|
@@ -141,7 +138,7 @@ class PovTest(unittest.TestCase):
|
|
141
138
|
Tree('c')
|
142
139
|
])
|
143
140
|
expected = ['x', 'parent', 'b']
|
144
|
-
self.assertEqual(tree.
|
141
|
+
self.assertEqual(tree.path_to('x', 'b'), expected)
|
145
142
|
|
146
143
|
def test_can_find_path_to_cousin(self):
|
147
144
|
tree = Tree('grandparent', [
|
@@ -159,7 +156,7 @@ class PovTest(unittest.TestCase):
|
|
159
156
|
])
|
160
157
|
])
|
161
158
|
expected = ['x', 'parent', 'grandparent', 'uncle', 'cousin-1']
|
162
|
-
self.assertEqual(tree.
|
159
|
+
self.assertEqual(tree.path_to('x', 'cousin-1'), expected)
|
163
160
|
|
164
161
|
def test_can_find_path_from_nodes_other_than_x(self):
|
165
162
|
tree = Tree('parent', [
|
@@ -169,7 +166,7 @@ class PovTest(unittest.TestCase):
|
|
169
166
|
Tree('c')
|
170
167
|
])
|
171
168
|
expected = ['a', 'parent', 'c']
|
172
|
-
self.assertEqual(tree.
|
169
|
+
self.assertEqual(tree.path_to('a', 'c'), expected)
|
173
170
|
|
174
171
|
def test_errors_if_destination_does_not_exist(self):
|
175
172
|
tree = Tree('parent', [
|
@@ -181,7 +178,7 @@ class PovTest(unittest.TestCase):
|
|
181
178
|
Tree('sibling-1')
|
182
179
|
])
|
183
180
|
with self.assertRaisesWithMessage(ValueError):
|
184
|
-
tree.
|
181
|
+
tree.path_to('x', 'nonexistent')
|
185
182
|
|
186
183
|
def test_errors_if_source_does_not_exist(self):
|
187
184
|
tree = Tree('parent', [
|
@@ -193,7 +190,7 @@ class PovTest(unittest.TestCase):
|
|
193
190
|
Tree('sibling-1')
|
194
191
|
])
|
195
192
|
with self.assertRaisesWithMessage(ValueError):
|
196
|
-
tree.
|
193
|
+
tree.path_to('nonexistent', 'x')
|
197
194
|
|
198
195
|
# Utility functions
|
199
196
|
def setUp(self):
|
@@ -205,6 +202,10 @@ class PovTest(unittest.TestCase):
|
|
205
202
|
def assertRaisesWithMessage(self, exception):
|
206
203
|
return self.assertRaisesRegex(exception, r".+")
|
207
204
|
|
205
|
+
def assertTreeEquals(self, result, expected):
|
206
|
+
self.assertEqual(result, expected,
|
207
|
+
'{} != {}'.format(result, expected))
|
208
|
+
|
208
209
|
|
209
210
|
if __name__ == '__main__':
|
210
211
|
unittest.main()
|
@@ -3,77 +3,67 @@ import unittest
|
|
3
3
|
from protein_translation import proteins
|
4
4
|
|
5
5
|
|
6
|
-
# Tests adapted from problem-specifications/canonical-data.json @ v1.
|
6
|
+
# Tests adapted from problem-specifications/canonical-data.json @ v1.1.0
|
7
7
|
|
8
8
|
class ProteinTranslationTests(unittest.TestCase):
|
9
9
|
|
10
10
|
def test_AUG_translates_to_methionine(self):
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(proteins('AUG'), ['Methionine'])
|
12
12
|
|
13
13
|
def test_identifies_Phenylalanine_codons(self):
|
14
14
|
for codon in ['UUU', 'UUC']:
|
15
|
-
self.assertEqual(['Phenylalanine']
|
15
|
+
self.assertEqual(proteins(codon), ['Phenylalanine'])
|
16
16
|
|
17
17
|
def test_identifies_Leucine_codons(self):
|
18
18
|
for codon in ['UUA', 'UUG']:
|
19
|
-
self.assertEqual(['Leucine']
|
19
|
+
self.assertEqual(proteins(codon), ['Leucine'])
|
20
20
|
|
21
21
|
def test_identifies_Serine_codons(self):
|
22
22
|
for codon in ['UCU', 'UCC', 'UCA', 'UCG']:
|
23
|
-
self.assertEqual(['Serine']
|
23
|
+
self.assertEqual(proteins(codon), ['Serine'])
|
24
24
|
|
25
25
|
def test_identifies_Tyrosine_codons(self):
|
26
26
|
for codon in ['UAU', 'UAC']:
|
27
|
-
self.assertEqual(['Tyrosine']
|
27
|
+
self.assertEqual(proteins(codon), ['Tyrosine'])
|
28
28
|
|
29
29
|
def test_identifies_Cysteine_codons(self):
|
30
30
|
for codon in ['UGU', 'UGC']:
|
31
|
-
self.assertEqual(['Cysteine']
|
31
|
+
self.assertEqual(proteins(codon), ['Cysteine'])
|
32
32
|
|
33
33
|
def test_identifies_Tryptophan_codons(self):
|
34
|
-
self.assertEqual(
|
34
|
+
self.assertEqual(proteins('UGG'), ['Tryptophan'])
|
35
35
|
|
36
36
|
def test_identifies_stop_codons(self):
|
37
37
|
for codon in ['UAA', 'UAG', 'UGA']:
|
38
|
-
self.assertEqual(
|
38
|
+
self.assertEqual(proteins(codon), [])
|
39
39
|
|
40
40
|
def test_translates_rna_strand_into_correct_protein_list(self):
|
41
41
|
strand = 'AUGUUUUGG'
|
42
42
|
expected = ['Methionine', 'Phenylalanine', 'Tryptophan']
|
43
|
-
self.assertEqual(
|
43
|
+
self.assertEqual(proteins(strand), expected)
|
44
44
|
|
45
45
|
def test_stops_translation_if_stop_codon_at_beginning_of_sequence(self):
|
46
46
|
strand = 'UAGUGG'
|
47
47
|
expected = []
|
48
|
-
self.assertEqual(
|
48
|
+
self.assertEqual(proteins(strand), expected)
|
49
49
|
|
50
50
|
def test_stops_translation_if_stop_codon_at_end_of_two_codon_sequence(
|
51
51
|
self):
|
52
52
|
strand = 'UGGUAG'
|
53
53
|
expected = ['Tryptophan']
|
54
|
-
self.assertEqual(
|
54
|
+
self.assertEqual(proteins(strand), expected)
|
55
55
|
|
56
56
|
def test_stops_translation_if_stop_codon_at_end_of_three_codon_sequence(
|
57
57
|
self):
|
58
58
|
strand = 'AUGUUUUAA'
|
59
59
|
expected = ['Methionine', 'Phenylalanine']
|
60
|
-
self.assertEqual(
|
60
|
+
self.assertEqual(proteins(strand), expected)
|
61
61
|
|
62
62
|
def test_stops_translation_if_stop_codon_in_middle_of_six_codon_sequence(
|
63
63
|
self):
|
64
64
|
strand = 'UGGUGUUAUUAAUGGUUU'
|
65
65
|
expected = ['Tryptophan', 'Cysteine', 'Tyrosine']
|
66
|
-
self.assertEqual(
|
67
|
-
|
68
|
-
# Utility functions
|
69
|
-
def setUp(self):
|
70
|
-
try:
|
71
|
-
self.assertRaisesRegex
|
72
|
-
except AttributeError:
|
73
|
-
self.assertRaisesRegex = self.assertRaisesRegexp
|
74
|
-
|
75
|
-
def assertRaisesWithMessage(self, exception):
|
76
|
-
return self.assertRaisesRegex(exception, r".+")
|
66
|
+
self.assertEqual(proteins(strand), expected)
|
77
67
|
|
78
68
|
|
79
69
|
if __name__ == '__main__':
|
@@ -3,7 +3,7 @@ import unittest
|
|
3
3
|
from rail_fence_cipher import encode, decode
|
4
4
|
|
5
5
|
|
6
|
-
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0
|
6
|
+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
|
7
7
|
|
8
8
|
class RailFenceTests(unittest.TestCase):
|
9
9
|
def test_encode_with_two_rails(self):
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Rational Numbers
|
2
|
+
|
3
|
+
A rational number is defined as the quotient of two integers `a` and `b`, called the numerator and denominator, respectively, where `b != 0`.
|
4
|
+
|
5
|
+
The absolute value `|r|` of the rational number `r = a/b` is equal to `|a|/|b|`.
|
6
|
+
|
7
|
+
The sum of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 + r2 = a1/b1 + a2/b2 = (a1 * b2 + a2 * b1) / (b1 * b2)`.
|
8
|
+
|
9
|
+
The difference of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 - r2 = a1/b1 - a2/b2 = (a1 * b2 - a2 * b1) / (b1 * b2)`.
|
10
|
+
|
11
|
+
The product (multiplication) of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 * r2 = (a1 * a2) / (b1 * b2)`.
|
12
|
+
|
13
|
+
Dividing a rational number `r1 = a1/b1` by another `r2 = a2/b2` is `r1 / r2 = (a1 * b2) / (a2 * b1)` if `a2 * b1` is not zero.
|
14
|
+
|
15
|
+
Exponentiation of a rational number `r = a/b` to a non-negative integer power `n` is `r^n = (a^n)/(b^n)`.
|
16
|
+
|
17
|
+
Exponentiation of a rational number `r = a/b` to a negative integer power `n` is `r^n = (b^m)/(a^m)`, where `m = |n|`.
|
18
|
+
|
19
|
+
Exponentiation of a rational number `r = a/b` to a real (floating-point) number `x` is the quotient `(a^x)/(b^x)`, which is a real number.
|
20
|
+
|
21
|
+
Exponentiation of a real number `x` to a rational number `r = a/b` is `x^(a/b) = root(x^a, b)`, where `root(p, q)` is the `q`th root of `p`.
|
22
|
+
|
23
|
+
Implement the following operations:
|
24
|
+
- addition, subtraction, multiplication and division of two rational numbers,
|
25
|
+
- absolute value, exponentiation of a given rational number to an integer power, exponentiation of a given rational number to a real (floating-point) power, exponentiation of a real number to a rational number.
|
26
|
+
|
27
|
+
Your implementation of rational numbers should always be reduced to lowest terms. For example, `4/4` should reduce to `1/1`, `30/60` should reduce to `1/2`, `12/8` should reduce to `3/2`, etc. To reduce a rational number `r = a/b`, divide `a` and `b` by the greatest common divisor (gcd) of `a` and `b`. So, for example, `gcd(12, 8) = 4`, so `r = 12/8` can be reduced to `(12/4)/(8/4) = 3/2`.
|
28
|
+
|
29
|
+
Assume that the programming language you are using does not have an implementation of rational numbers.
|
30
|
+
|
31
|
+
## Exception messages
|
32
|
+
|
33
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
34
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
35
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
36
|
+
a message.
|
37
|
+
|
38
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
39
|
+
`raise Exception`, you shold write:
|
40
|
+
|
41
|
+
```python
|
42
|
+
raise Exception("Meaningful message indicating the source of the error")
|
43
|
+
```
|
44
|
+
|
45
|
+
## Submitting Exercises
|
46
|
+
|
47
|
+
Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/rational-numbers` directory.
|
48
|
+
|
49
|
+
You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.
|
50
|
+
|
51
|
+
For more detailed information about running tests, code style and linting,
|
52
|
+
please see the [help page](http://exercism.io/languages/python).
|
53
|
+
|
54
|
+
## Source
|
55
|
+
|
56
|
+
Wikipedia [https://en.wikipedia.org/wiki/Rational_number](https://en.wikipedia.org/wiki/Rational_number)
|
57
|
+
|
58
|
+
## Submitting Incomplete Solutions
|
59
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
from __future__ import division
|
2
|
+
|
3
|
+
from fractions import gcd
|
4
|
+
|
5
|
+
|
6
|
+
class Rational(object):
|
7
|
+
"""
|
8
|
+
Toyish implementation of rational numbers. For production purpose,
|
9
|
+
please use `fractions.Fraction` in standard library instead.
|
10
|
+
"""
|
11
|
+
def __init__(self, numer, denom):
|
12
|
+
self.numer, self.denom = self._reduce(numer, denom)
|
13
|
+
|
14
|
+
def _reduce(self, numer, denom):
|
15
|
+
if numer == 0:
|
16
|
+
n, d = 0, 1
|
17
|
+
else:
|
18
|
+
g = gcd(numer, denom)
|
19
|
+
n, d = int(numer/g), int(denom/g)
|
20
|
+
if n > 0 and d < 0:
|
21
|
+
n, d = -n, -d
|
22
|
+
return n, d
|
23
|
+
|
24
|
+
def __eq__(self, other):
|
25
|
+
return self.numer == other.numer and self.denom == other.denom
|
26
|
+
|
27
|
+
def __repr__(self):
|
28
|
+
return '{}/{}'.format(self.numer, self.denom)
|
29
|
+
|
30
|
+
def __add__(self, other):
|
31
|
+
return Rational(
|
32
|
+
self.numer*other.denom + self.denom*other.numer,
|
33
|
+
self.denom*other.denom
|
34
|
+
)
|
35
|
+
|
36
|
+
def __sub__(self, other):
|
37
|
+
return Rational(
|
38
|
+
self.numer*other.denom - self.denom*other.numer,
|
39
|
+
self.denom*other.denom
|
40
|
+
)
|
41
|
+
|
42
|
+
def __mul__(self, other):
|
43
|
+
return Rational(self.numer * other.numer, self.denom * other.denom)
|
44
|
+
|
45
|
+
def __truediv__(self, other):
|
46
|
+
return Rational(self.numer * other.denom, self.denom * other.numer)
|
47
|
+
|
48
|
+
def __abs__(self):
|
49
|
+
if self.numer >= 0:
|
50
|
+
return self
|
51
|
+
else:
|
52
|
+
return Rational(-self.numer, self.denom)
|
53
|
+
|
54
|
+
def __pow__(self, power):
|
55
|
+
return Rational(self.numer ** power, self.denom ** power)
|
56
|
+
|
57
|
+
def __rpow__(self, base):
|
58
|
+
return base ** (self.numer / self.denom)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from __future__ import division
|
2
|
+
|
3
|
+
|
4
|
+
class Rational(object):
|
5
|
+
def __init__(self, numer, denom):
|
6
|
+
self.numer = None
|
7
|
+
self.denom = None
|
8
|
+
|
9
|
+
def __eq__(self, other):
|
10
|
+
return self.numer == other.numer and self.denom == other.denom
|
11
|
+
|
12
|
+
def __repr__(self):
|
13
|
+
return '{}/{}'.format(self.numer, self.denom)
|
14
|
+
|
15
|
+
def __add__(self, other):
|
16
|
+
pass
|
17
|
+
|
18
|
+
def __sub__(self, other):
|
19
|
+
pass
|
20
|
+
|
21
|
+
def __mul__(self, other):
|
22
|
+
pass
|
23
|
+
|
24
|
+
def __truediv__(self, other):
|
25
|
+
pass
|
26
|
+
|
27
|
+
def __abs__(self):
|
28
|
+
pass
|
29
|
+
|
30
|
+
def __pow__(self, power):
|
31
|
+
pass
|
32
|
+
|
33
|
+
def __rpow__(self, base):
|
34
|
+
pass
|
@@ -0,0 +1,132 @@
|
|
1
|
+
from __future__ import division
|
2
|
+
|
3
|
+
import unittest
|
4
|
+
|
5
|
+
from rational_numbers import Rational
|
6
|
+
|
7
|
+
|
8
|
+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
|
9
|
+
|
10
|
+
class RationalTests(unittest.TestCase):
|
11
|
+
|
12
|
+
# Test addition
|
13
|
+
def test_add_two_positive(self):
|
14
|
+
self.assertEqual(Rational(1, 2) + Rational(2, 3), Rational(7, 6))
|
15
|
+
|
16
|
+
def test_add_positive_and_negative(self):
|
17
|
+
self.assertEqual(Rational(1, 2) + Rational(-2, 3), Rational(-1, 6))
|
18
|
+
|
19
|
+
def test_add_two_negative(self):
|
20
|
+
self.assertEqual(Rational(-1, 2) + Rational(-2, 3), Rational(-7, 6))
|
21
|
+
|
22
|
+
def test_add_opposite(self):
|
23
|
+
self.assertEqual(Rational(1, 2) + Rational(-1, 2), Rational(0, 1))
|
24
|
+
|
25
|
+
# Test subtraction
|
26
|
+
def test_subtract_two_positive(self):
|
27
|
+
self.assertEqual(Rational(1, 2) - Rational(2, 3), Rational(-1, 6))
|
28
|
+
|
29
|
+
def test_subtract_positive_and_negative(self):
|
30
|
+
self.assertEqual(Rational(1, 2) - Rational(-2, 3), Rational(7, 6))
|
31
|
+
|
32
|
+
def test_subtract_two_negative(self):
|
33
|
+
self.assertEqual(Rational(-1, 2) - Rational(-2, 3), Rational(1, 6))
|
34
|
+
|
35
|
+
def test_subtract_from_self(self):
|
36
|
+
self.assertEqual(Rational(1, 2) - Rational(1, 2), Rational(0, 1))
|
37
|
+
|
38
|
+
# Test multiplication
|
39
|
+
def test_multiply_two_positive(self):
|
40
|
+
self.assertEqual(Rational(1, 2) * Rational(2, 3), Rational(1, 3))
|
41
|
+
|
42
|
+
def test_multiply_negative_by_positive(self):
|
43
|
+
self.assertEqual(Rational(-1, 2) * Rational(2, 3), Rational(-1, 3))
|
44
|
+
|
45
|
+
def test_multiply_two_negative(self):
|
46
|
+
self.assertEqual(Rational(-1, 2) * Rational(-2, 3), Rational(1, 3))
|
47
|
+
|
48
|
+
def test_multiply_reciprocal(self):
|
49
|
+
self.assertEqual(Rational(1, 2) * Rational(2, 1), Rational(1, 1))
|
50
|
+
|
51
|
+
def test_multiply_by_one(self):
|
52
|
+
self.assertEqual(Rational(1, 2) * Rational(1, 1), Rational(1, 2))
|
53
|
+
|
54
|
+
def test_multiply_by_zero(self):
|
55
|
+
self.assertEqual(Rational(1, 2) * Rational(0, 1), Rational(0, 1))
|
56
|
+
|
57
|
+
# Test division
|
58
|
+
def test_divide_two_positive(self):
|
59
|
+
self.assertEqual(Rational(1, 2) / Rational(2, 3), Rational(3, 4))
|
60
|
+
|
61
|
+
def test_divide_positive_by_negative(self):
|
62
|
+
self.assertEqual(Rational(1, 2) / Rational(-2, 3), Rational(-3, 4))
|
63
|
+
|
64
|
+
def test_divide_two_negative(self):
|
65
|
+
self.assertEqual(Rational(-1, 2) / Rational(-2, 3), Rational(3, 4))
|
66
|
+
|
67
|
+
def test_divide_by_one(self):
|
68
|
+
self.assertEqual(Rational(1, 2) / Rational(1, 1), Rational(1, 2))
|
69
|
+
|
70
|
+
# Test absolute value
|
71
|
+
def test_absolute_value_of_positive(self):
|
72
|
+
self.assertEqual(abs(Rational(1, 2)), Rational(1, 2))
|
73
|
+
|
74
|
+
def test_absolute_value_of_negative(self):
|
75
|
+
self.assertEqual(abs(Rational(-1, 2)), Rational(1, 2))
|
76
|
+
|
77
|
+
def test_absolute_value_of_zero(self):
|
78
|
+
self.assertEqual(abs(Rational(0, 1)), Rational(0, 1))
|
79
|
+
|
80
|
+
# Test exponentiation of a rational number
|
81
|
+
def test_raise_a_positive_rational_to_a_positive_integer_power(self):
|
82
|
+
self.assertEqual(Rational(1, 2) ** 3, Rational(1, 8))
|
83
|
+
|
84
|
+
def test_raise_a_negative_rational_to_a_positive_integer_power(self):
|
85
|
+
self.assertEqual(Rational(-1, 2) ** 3, Rational(-1, 8))
|
86
|
+
|
87
|
+
def test_raise_zero_to_an_integer_power(self):
|
88
|
+
self.assertEqual(Rational(0, 1) ** 5, Rational(0, 1))
|
89
|
+
|
90
|
+
def test_raise_one_to_an_integer_power(self):
|
91
|
+
self.assertEqual(Rational(1, 1) ** 4, Rational(1, 1))
|
92
|
+
|
93
|
+
def test_raise_a_positive_rational_to_the_power_of_zero(self):
|
94
|
+
self.assertEqual(Rational(1, 2) ** 0, Rational(1, 1))
|
95
|
+
|
96
|
+
def test_raise_a_negative_rational_to_the_power_of_zero(self):
|
97
|
+
self.assertEqual(Rational(-1, 2) ** 0, Rational(1, 1))
|
98
|
+
|
99
|
+
# Test exponentiation of a real number to a rational number
|
100
|
+
def test_raise_a_real_number_to_a_positive_rational(self):
|
101
|
+
self.assertAlmostEqual(8 ** Rational(4, 3), 16.0, places=8)
|
102
|
+
|
103
|
+
def test_raise_a_real_number_to_a_negative_rational(self):
|
104
|
+
self.assertAlmostEqual(
|
105
|
+
9 ** Rational(-1, 2), 0.3333333333333333, places=8
|
106
|
+
)
|
107
|
+
|
108
|
+
def test_raise_a_real_number_to_a_zero_rational(self):
|
109
|
+
self.assertAlmostEqual(2 ** Rational(0, 1), 1.0, places=8)
|
110
|
+
|
111
|
+
# Test reduction to lowest terms
|
112
|
+
def test_reduce_positive(self):
|
113
|
+
self.assertEqual(Rational(2, 4), Rational(1, 2))
|
114
|
+
|
115
|
+
def test_reduce_negative(self):
|
116
|
+
self.assertEqual(Rational(-4, 6), Rational(-2, 3))
|
117
|
+
|
118
|
+
def test_reduce_rational_with_negative_denominator(self):
|
119
|
+
self.assertEqual(Rational(3, -9), Rational(-1, 3))
|
120
|
+
|
121
|
+
def test_reduce_zero(self):
|
122
|
+
self.assertEqual(Rational(0, 6), Rational(0, 1))
|
123
|
+
|
124
|
+
def test_reduce_integer(self):
|
125
|
+
self.assertEqual(Rational(-14, 7), Rational(-2, 1))
|
126
|
+
|
127
|
+
def test_reduce_one(self):
|
128
|
+
self.assertEqual(Rational(13, 13), Rational(1, 1))
|
129
|
+
|
130
|
+
|
131
|
+
if __name__ == '__main__':
|
132
|
+
unittest.main()
|