beginner.codes 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +13 -3
  4. data/lib/challenges.rb +23 -3
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8de84d0cc7092d0bcb44af92ce102a8e94077a42e44dff82f2b115651109e71
4
- data.tar.gz: 3f7e092d43c8df7e34aceb6546af41b423ba77bd773b248e4e461678a7235eda
3
+ metadata.gz: ff8827c1454a8d44b7ebd23a4c6c2b0c6f73e6502643630b0de30434d54ca424
4
+ data.tar.gz: f845377f0f7e3e4ce5a5446fcea9196c9d3ebe411b778c7708c508f200de5c3c
5
5
  SHA512:
6
- metadata.gz: 309b1e6659355f613667320920e2b677b183d61f8f6914817566fd2d8e3acae5ed83b44c9f332f61f6eaf6cd9fec689bf6a5e2bf182104d89a9cd126da9b5b2d
7
- data.tar.gz: c6437f9788090fc7ccc199f8ae28bb70f94190eed11d42a26ea0aa36185c71db2b400ba49b294b0779a4b6152c454bc7ce3ae333d23f390ae0a8e889e8610587
6
+ metadata.gz: ca8ca526d9026fcb0fe9745c96f801c9e210a8c761cbb973014d644d3c3ccdb5dd9426e52d5e2b03488bacf38afc290b79ded83db2f7c9bfe8f41e89b2157af5
7
+ data.tar.gz: 9fff417792131a316f81e47ecd08e29798f8d0d3ff548aeda9de2457c2e18f2257c1c431614dfdcaeff9434015359f4564e65333aeb51fedec5731c070923d07
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ # 0.1.5 (9 November 2023)
2
+
3
+ ---
4
+
5
+ ## Enhancements
6
+
7
+ - Added two arguments passed to test `description: true` and `examples: true` to print out additional challenge data during testing
8
+
9
+ ## Bug Fixes
10
+
11
+ ## Performance
12
+
13
+ ## Documentation
14
+
15
+ - Updated README to include the new arguments
16
+ - Thanksgiving approaches along with the cruel realization that I never lost the weight from last new years.
17
+
18
+ ---
19
+
20
+ # 0.1.4 (7 November 2023)
21
+
22
+ ---
23
+
24
+ ## Enhancements
25
+
26
+ - Added ability to process lambda functions.
27
+
28
+ ## Bug Fixes
29
+
30
+ ## Performance
31
+
32
+ - It is now .0001% faster
33
+
34
+ ## Documentation
35
+
36
+ - Updated README to include the lambda function syntax
37
+ - Sometimes I wonder if I'm living in a simulation. If so, why does my player always have me go into a room and forget why I went in.
38
+
39
+ ---
40
+
1
41
  # 0.1.3 (1 November 2023)
2
42
 
3
43
  ---
data/README.md CHANGED
@@ -6,7 +6,7 @@ This is the un-official Ruby Gem for the Beginner.Codes Discord server.
6
6
 
7
7
  - Install the package: `gem install beginner.codes`
8
8
  - Import the test runner: `require 'challenges'`
9
- - Run the tests, passing in the challenge number and your solution function: `test(458, n_differences)`
9
+ - Run the tests, passing in the challenge number and your solution function: `test(458, :n_differences)` for a function or `test(458, n_differences)` for a lambda function
10
10
  ```ruby
11
11
  require 'challenges'
12
12
 
@@ -14,7 +14,17 @@ def n_differences(nums)
14
14
  nil
15
15
  end # Your code goes here!!!
16
16
 
17
-
18
17
  test(458, :n_differences)
18
+
19
+ # OR You can use a Lambda Proc
20
+
21
+ n_differences = -> (x) {x*2}
22
+
23
+ test(458, n_differences)
19
24
  ```
20
- This will handle downloading the necessary challenge test cases and will run them against your code. It will show you which tests failed, what went wrong, and how many tests succeeded.
25
+ This will handle downloading the necessary challenge test cases and will run them against your code. It will show you which tests failed, what went wrong, and how many tests succeeded.
26
+
27
+ Additionally, you can view the description and examples when running the tests by adding some options to the test function
28
+ ```ruby
29
+ test(458, :n_differences, description: true, examples: true)
30
+ ```
data/lib/challenges.rb CHANGED
@@ -4,7 +4,10 @@ require 'json'
4
4
  require 'uri'
5
5
  require 'net/http'
6
6
  require 'colorize'
7
+ require 'tty-markdown'
7
8
 
9
+ TEST_CASE_URL = 'https://raw.githubusercontent.com/beginner-codes/challenges/main/weekday/test_cases_'
10
+ DESCRIPTION_URL = 'https://raw.githubusercontent.com/beginner-codes/challenges/main/weekday/challenge_'
8
11
 
9
12
  module Status
10
13
  SUCCESS = 1
@@ -25,9 +28,20 @@ class Result
25
28
  end
26
29
  end
27
30
 
31
+ # fetches the description from source
32
+ def puts_info(challenge, description, examples)
33
+ url = URI(DESCRIPTION_URL + "#{challenge}.md")
34
+ response = Net::HTTP.get(url).force_encoding('UTF-8')
35
+ result = "\n"
36
+ result += response.split('## ').first.gsub("\n\n", "\n")+"\n" if description
37
+ result += response.split('#')[3].gsub("\n\n", "\n").insert(0,'#') if examples
38
+ result = TTY::Markdown.parse(result)
39
+ puts result
40
+ end
41
+
28
42
  # fetches the result from the source
29
43
  def get_tests(challenge)
30
- uri = URI("https://raw.githubusercontent.com/beginner-codes/challenges/main/weekday/test_cases_#{challenge}.json")
44
+ uri = URI(TEST_CASE_URL + "#{challenge}.json")
31
45
  response = Net::HTTP.get_response(uri)
32
46
  raise "Challenge #{challenge} was not found" unless response.is_a?(Net::HTTPSuccess)
33
47
 
@@ -41,7 +55,12 @@ def run_tests(tests, solution_func)
41
55
  tests.each_with_index do |test_case, index|
42
56
  result = Result.new(index, test_case['return'])
43
57
  begin
44
- result.got = send(solution_func, *test_case['args'])
58
+ result.got = if solution_func.is_a?(Proc)
59
+ solution_func.call(*test_case['args'])
60
+ else
61
+ send(solution_func, *test_case['args'])
62
+ end
63
+
45
64
  rescue StandardError => e
46
65
  result.status = Status::EXCEPTION
47
66
  result.got = e
@@ -72,8 +91,9 @@ def show_results(challenge, results, total_tests)
72
91
  end
73
92
 
74
93
  # the main entry point function
75
- def test(challenge, solution_func)
94
+ def test(challenge, solution_func, description: false, examples: false)
76
95
  tests = get_tests(challenge)
96
+ puts_info(challenge, description, examples) if description || examples
77
97
  results = run_tests(tests, solution_func)
78
98
  show_results(challenge, results, tests.size)
79
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beginner.codes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mr. Robinhood 5
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-11-02 00:00:00.000000000 Z
12
+ date: 2023-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: tty-markdown
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.7.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.7.2
28
42
  description: This is the un-official RubyGem for the Beginner.Codes Discord server.
29
43
  Test your daily challenge solutions with provided tests automatically to ensure
30
44
  you have a good solution.