leap
This commit is contained in:
		
							parent
							
								
									eaf2ddb913
								
							
						
					
					
						commit
						f3067bce0f
					
				
							
								
								
									
										35
									
								
								elixir/leap/.exercism/config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								elixir/leap/.exercism/config.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| { | ||||
|   "authors": [ | ||||
|     "rubysolo" | ||||
|   ], | ||||
|   "contributors": [ | ||||
|     "angelikatyborska", | ||||
|     "Cohen-Carlisle", | ||||
|     "dalexj", | ||||
|     "devonestes", | ||||
|     "glennular", | ||||
|     "jinyeow", | ||||
|     "korbin", | ||||
|     "kytrinyx", | ||||
|     "lpil", | ||||
|     "neenjaw", | ||||
|     "parkerl", | ||||
|     "sotojuan", | ||||
|     "Teapane", | ||||
|     "waiting-for-dev" | ||||
|   ], | ||||
|   "files": { | ||||
|     "solution": [ | ||||
|       "lib/year.ex" | ||||
|     ], | ||||
|     "test": [ | ||||
|       "test/year_test.exs" | ||||
|     ], | ||||
|     "example": [ | ||||
|       ".meta/example.ex" | ||||
|     ] | ||||
|   }, | ||||
|   "blurb": "Given a year, report if it is a leap year.", | ||||
|   "source": "CodeRanch Cattle Drive, Assignment 3", | ||||
|   "source_url": "https://coderanch.com/t/718816/Leap" | ||||
| } | ||||
							
								
								
									
										1
									
								
								elixir/leap/.exercism/metadata.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								elixir/leap/.exercism/metadata.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| {"track":"elixir","exercise":"leap","id":"8bd50f0b5d7c4308bca361b49e63d755","url":"https://exercism.org/tracks/elixir/exercises/leap","handle":"negrienko","is_requester":true,"auto_approve":false} | ||||
							
								
								
									
										4
									
								
								elixir/leap/.formatter.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								elixir/leap/.formatter.exs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| # Used by "mix format" | ||||
| [ | ||||
|   inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||||
| ] | ||||
							
								
								
									
										24
									
								
								elixir/leap/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								elixir/leap/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| # The directory Mix will write compiled artifacts to. | ||||
| /_build/ | ||||
| 
 | ||||
| # If you run "mix test --cover", coverage assets end up here. | ||||
| /cover/ | ||||
| 
 | ||||
| # The directory Mix downloads your dependencies sources to. | ||||
| /deps/ | ||||
| 
 | ||||
| # Where third-party dependencies like ExDoc output generated docs. | ||||
| /doc/ | ||||
| 
 | ||||
| # Ignore .fetch files in case you like to edit your project deps locally. | ||||
| /.fetch | ||||
| 
 | ||||
| # If the VM crashes, it generates a dump, let's ignore it too. | ||||
| erl_crash.dump | ||||
| 
 | ||||
| # Also ignore archive artifacts (built via "mix archive.build"). | ||||
| *.ez | ||||
| 
 | ||||
| # Ignore package tarball (built via "mix hex.build"). | ||||
| leap-*.tar | ||||
| 
 | ||||
							
								
								
									
										75
									
								
								elixir/leap/HELP.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								elixir/leap/HELP.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,75 @@ | ||||
| # Help | ||||
| 
 | ||||
| ## Running the tests | ||||
| 
 | ||||
| From the terminal, change to the base directory of the exercise then execute the tests with: | ||||
| 
 | ||||
| ```bash | ||||
| $ mix test | ||||
| ``` | ||||
| 
 | ||||
| This will execute the test file found in the `test` subfolder -- a file ending in `_test.exs` | ||||
| 
 | ||||
| Documentation: | ||||
| 
 | ||||
| * [`mix test` - Elixir's test execution tool](https://hexdocs.pm/mix/Mix.Tasks.Test.html) | ||||
| * [`ExUnit` - Elixir's unit test library](https://hexdocs.pm/ex_unit/ExUnit.html) | ||||
| 
 | ||||
| ## Pending tests | ||||
| 
 | ||||
| In test suites of practice exercises, all but the first test have been tagged to be skipped. | ||||
| 
 | ||||
| Once you get a test passing, you can unskip the next one by commenting out the relevant `@tag :pending` with a `#` symbol. | ||||
| 
 | ||||
| For example: | ||||
| 
 | ||||
| ```elixir | ||||
| # @tag :pending | ||||
| test "shouting" do | ||||
|   assert Bob.hey("WATCH OUT!") == "Whoa, chill out!" | ||||
| end | ||||
| ``` | ||||
| 
 | ||||
| If you wish to run all tests at once, you can include all skipped test by using the `--include` flag on the `mix test` command: | ||||
| 
 | ||||
| ```bash | ||||
| $ mix test --include pending | ||||
| ``` | ||||
| 
 | ||||
| Or, you can enable all the tests by commenting out the `ExUnit.configure` line in the file `test/test_helper.exs`. | ||||
| 
 | ||||
| ```elixir | ||||
| # ExUnit.configure(exclude: :pending, trace: true) | ||||
| ``` | ||||
| 
 | ||||
| ## Useful `mix test` options | ||||
| 
 | ||||
| * `test/<FILE>.exs:LINENUM` - runs only a single test, the test from `<FILE>.exs` whose definition is on line `LINENUM` | ||||
| * `--failed` - runs only tests that failed the last time they ran | ||||
| * `--max-failures` - the suite stops evaluating tests when this number of test failures | ||||
| is reached | ||||
| * `--seed 0` - disables randomization so the tests in a single file will always be ran | ||||
| in the same order they were defined in | ||||
| 
 | ||||
| ## Submitting your solution | ||||
| 
 | ||||
| You can submit your solution using the `exercism submit lib/year.ex` command. | ||||
| This command will upload your solution to the Exercism website and print the solution page's URL. | ||||
| 
 | ||||
| It's possible to submit an incomplete solution which allows you to: | ||||
| 
 | ||||
| - See how others have completed the exercise | ||||
| - Request help from a mentor | ||||
| 
 | ||||
| ## Need to get help? | ||||
| 
 | ||||
| If you'd like help solving the exercise, check the following pages: | ||||
| 
 | ||||
| - The [Elixir track's documentation](https://exercism.org/docs/tracks/elixir) | ||||
| - The [Elixir track's programming category on the forum](https://forum.exercism.org/c/programming/elixir) | ||||
| - [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) | ||||
| - The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) | ||||
| 
 | ||||
| Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. | ||||
| 
 | ||||
| If you're stuck on something, it may help to look at some of the [available resources](https://exercism.org/docs/tracks/elixir/resources) out there where answers might be found. | ||||
							
								
								
									
										54
									
								
								elixir/leap/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								elixir/leap/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| # Leap | ||||
| 
 | ||||
| Welcome to Leap on Exercism's Elixir Track. | ||||
| If you need help running the tests or submitting your code, check out `HELP.md`. | ||||
| 
 | ||||
| ## Instructions | ||||
| 
 | ||||
| Given a year, report if it is a leap year. | ||||
| 
 | ||||
| The tricky thing here is that a leap year in the Gregorian calendar occurs: | ||||
| 
 | ||||
| ```text | ||||
| on every year that is evenly divisible by 4 | ||||
|   except every year that is evenly divisible by 100 | ||||
|     unless the year is also evenly divisible by 400 | ||||
| ``` | ||||
| 
 | ||||
| For example, 1997 is not a leap year, but 1996 is. | ||||
| 1900 is not a leap year, but 2000 is. | ||||
| 
 | ||||
| ## Notes | ||||
| 
 | ||||
| Though our exercise adopts some very simple rules, there is more to learn! | ||||
| 
 | ||||
| For a delightful, four minute explanation of the whole leap year phenomenon, go watch [this youtube video][video]. | ||||
| 
 | ||||
| [video]: https://www.youtube.com/watch?v=xX96xng7sAE | ||||
| 
 | ||||
| ## Source | ||||
| 
 | ||||
| ### Created by | ||||
| 
 | ||||
| - @rubysolo | ||||
| 
 | ||||
| ### Contributed to by | ||||
| 
 | ||||
| - @angelikatyborska | ||||
| - @Cohen-Carlisle | ||||
| - @dalexj | ||||
| - @devonestes | ||||
| - @glennular | ||||
| - @jinyeow | ||||
| - @korbin | ||||
| - @kytrinyx | ||||
| - @lpil | ||||
| - @neenjaw | ||||
| - @parkerl | ||||
| - @sotojuan | ||||
| - @Teapane | ||||
| - @waiting-for-dev | ||||
| 
 | ||||
| ### Based on | ||||
| 
 | ||||
| CodeRanch Cattle Drive, Assignment 3 - https://coderanch.com/t/718816/Leap | ||||
							
								
								
									
										16
									
								
								elixir/leap/lib/year.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								elixir/leap/lib/year.ex
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| defmodule Year do | ||||
|   @doc """ | ||||
|   Returns whether 'year' is a leap year. | ||||
| 
 | ||||
|   A leap year occurs: | ||||
| 
 | ||||
|   on every year that is evenly divisible by 4 | ||||
|     except every year that is evenly divisible by 100 | ||||
|       unless the year is also evenly divisible by 400 | ||||
|   """ | ||||
|   @spec leap_year?(non_neg_integer) :: boolean | ||||
|   def leap_year?(year) when rem(year, 400) == 0, do: true | ||||
|   def leap_year?(year) when rem(year, 100) == 0, do: false | ||||
|   def leap_year?(year) when rem(year, 4) == 0, do: true | ||||
|   def leap_year?(_year), do: false | ||||
| end | ||||
							
								
								
									
										28
									
								
								elixir/leap/mix.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								elixir/leap/mix.exs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| defmodule Year.MixProject do | ||||
|   use Mix.Project | ||||
| 
 | ||||
|   def project do | ||||
|     [ | ||||
|       app: :year, | ||||
|       version: "0.1.0", | ||||
|       # elixir: "~> 1.8", | ||||
|       start_permanent: Mix.env() == :prod, | ||||
|       deps: deps() | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   # Run "mix help compile.app" to learn about applications. | ||||
|   def application do | ||||
|     [ | ||||
|       extra_applications: [:logger] | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   # Run "mix help deps" to learn about dependencies. | ||||
|   defp deps do | ||||
|     [ | ||||
|       # {:dep_from_hexpm, "~> 0.3.0"}, | ||||
|       # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} | ||||
|     ] | ||||
|   end | ||||
| end | ||||
							
								
								
									
										2
									
								
								elixir/leap/test/test_helper.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								elixir/leap/test/test_helper.exs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| ExUnit.start() | ||||
| ExUnit.configure(exclude: :pending, trace: true) | ||||
							
								
								
									
										48
									
								
								elixir/leap/test/year_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								elixir/leap/test/year_test.exs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| defmodule YearTest do | ||||
|   use ExUnit.Case | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year not divisible by 4 is common year" do | ||||
|     refute Year.leap_year?(2015) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 2, not divisible by 4 is common year" do | ||||
|     refute Year.leap_year?(1970) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 4, not divisible by 100 is leap year" do | ||||
|     assert Year.leap_year?(1996) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 4 and 5 is still a leap year" do | ||||
|     assert Year.leap_year?(1960) | ||||
|   end | ||||
| 
 | ||||
|   @tag :pending | ||||
|   test "year divisible by 100, not divisible by 400 is common year" do | ||||
|     refute Year.leap_year?(2100) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 100 but not by 3 is still not a leap year" do | ||||
|     refute Year.leap_year?(1900) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 400 is leap year" do | ||||
|     assert Year.leap_year?(2000) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 400 but not by 125 is still a leap year" do | ||||
|     assert Year.leap_year?(2400) | ||||
|   end | ||||
| 
 | ||||
|   # @tag :pending | ||||
|   test "year divisible by 200, not divisible by 400 in common year" do | ||||
|     refute Year.leap_year?(1800) | ||||
|   end | ||||
| end | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user