beginner.codes 0.1.2 → 0.1.4

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 +5 -0
  4. data/lib/challenges.rb +15 -8
  5. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5006bebba31f4e53f2ed1aaf47e71c64522097718fbe76987cc75260a13b5a9
4
- data.tar.gz: d96051234873574596354dbb7ac583c0e9b1c680091212a10ea22f6e55b8fd3f
3
+ metadata.gz: 53a61ed7bdf941612a9b872243a1735c99e6510a0f787488654fd5cb0f57183e
4
+ data.tar.gz: 749500774942cd631b2c7f072f42e0bd6ed703791a8d97fdbec0a8b34367928e
5
5
  SHA512:
6
- metadata.gz: 074fd4a63171990caa85cf13a1892e6a76685f4e72581024b5de46761bf11663792cf829fd8c1fe50abd95224bd99dfa7e8e68ff7540f91b8461509f40dcfcea
7
- data.tar.gz: f72cacb87dcee5406547eb1d87bca7c585b6b3ded39fae93b4fdc3d4a8aadfda6a9e20fe9a2eab599063c75b3b038fa2f19936bab446846362519c38f1ed634b
6
+ metadata.gz: 944c7ac5de055f6f919537b62525ee86135c50add2fbbabe53cfd95e58bc39db9aadf5718504ce0bd7b41396279649824a13b733a2b4c9dc8453955482f97ad2
7
+ data.tar.gz: ea7009f4fc91cfdb3d339e9d676138ca0f98c12d96762ca2a65f876810557c3d4d4098563752dc96250dd92af575d42a20eef5a199f19d37df2f89ab889a584e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ # 0.1.4 (7 November 2023)
2
+
3
+ ---
4
+
5
+ ## Enhancements
6
+
7
+ - Added ability to process lambda functions.
8
+
9
+ ## Bug Fixes
10
+
11
+ ## Performance
12
+
13
+ - It is now .0001% faster
14
+
15
+ ## Documentation
16
+
17
+ - Updated README to include the lambda function syntax
18
+ - 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.
19
+
20
+ ---
21
+
22
+ # 0.1.3 (1 November 2023)
23
+
24
+ ---
25
+
26
+ ## Enhancements
27
+
28
+ - Added some colors via the 'colorize' gem to make it a little more clear what the expected and received answers were.
29
+
30
+ ## Bug Fixes
31
+
32
+ ## Performance
33
+
34
+ ## Documentation
35
+
36
+ - Added comments to make code 10.25% more helpful
37
+ - Sometimes I feel I've got to <> <> run away.. I've got to <> <> get away..
38
+
39
+ ---
40
+
1
41
  # 0.1.2 (27 October 2023)
2
42
 
3
43
  ---
data/README.md CHANGED
@@ -14,6 +14,11 @@ def n_differences(nums)
14
14
  nil
15
15
  end # Your code goes here!!!
16
16
 
17
+ test(458, :n_differences)
18
+
19
+ # OR You can use a Lambda Proc
20
+
21
+ n_differences = -> (x) {x*2}
17
22
 
18
23
  test(458, n_differences)
19
24
  ```
data/lib/challenges.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'json'
4
4
  require 'uri'
5
5
  require 'net/http'
6
+ require 'colorize'
6
7
 
7
- # this gets imported to your file
8
8
 
9
9
  module Status
10
10
  SUCCESS = 1
@@ -25,10 +25,9 @@ class Result
25
25
  end
26
26
  end
27
27
 
28
-
28
+ # fetches the result from the source
29
29
  def get_tests(challenge)
30
30
  uri = URI("https://raw.githubusercontent.com/beginner-codes/challenges/main/weekday/test_cases_#{challenge}.json")
31
- # uri = URI("https://raw.githubusercontent.com/beginner-codes/challenges/bfb59fe9fbec461a33cc80b20d1d976e9095853c/weekday/test_cases_#{challenge}.json")
32
31
  response = Net::HTTP.get_response(uri)
33
32
  raise "Challenge #{challenge} was not found" unless response.is_a?(Net::HTTPSuccess)
34
33
 
@@ -36,12 +35,18 @@ def get_tests(challenge)
36
35
 
37
36
  end
38
37
 
38
+ # parses your functions and checks if it passes
39
39
  def run_tests(tests, solution_func)
40
40
  results = []
41
41
  tests.each_with_index do |test_case, index|
42
42
  result = Result.new(index, test_case['return'])
43
43
  begin
44
- result.got = send(solution_func, *test_case['args'])
44
+ result.got = if solution_func.is_a?(Proc)
45
+ solution_func.call(*test_case['args'])
46
+ else
47
+ send(solution_func, *test_case['args'])
48
+ end
49
+
45
50
  rescue StandardError => e
46
51
  result.status = Status::EXCEPTION
47
52
  result.got = e
@@ -53,11 +58,12 @@ def run_tests(tests, solution_func)
53
58
  results
54
59
  end
55
60
 
61
+ # displays the results on the terminal
56
62
  def show_results(challenge, results, total_tests)
57
63
  failures = 0
58
64
  results.each do |result|
59
65
  if result.status.equal?(Status::FAILED)
60
- puts "Test #{result.index} failed: Expected #{result.expected}, got #{result.got}."
66
+ puts "Test #{result.index.to_s.blue} failed: Expected #{result.expected.to_s.green}, got #{result.got.to_s.red}"
61
67
  failures += 1
62
68
  elsif result.status.equal?(Status::EXCEPTION)
63
69
  puts "Test #{result.index} failed: #{result.got}"
@@ -65,11 +71,12 @@ def show_results(challenge, results, total_tests)
65
71
  end
66
72
  end
67
73
  puts ' ' if failures
68
- puts "---- Challenge #{challenge} Results ----"
69
- puts "#{total_tests - failures} passed, #{failures} failed"
70
- puts "\n**** Great job!!! ****" if failures.zero?
74
+ puts "---- Challenge #{challenge} Results ----".light_yellow.on_black
75
+ puts "#{(total_tests - failures).to_s.green} passed, #{failures.to_s.red} failed"
76
+ puts "\n**** Great job!!! ****".green if failures.zero?
71
77
  end
72
78
 
79
+ # the main entry point function
73
80
  def test(challenge, solution_func)
74
81
  tests = get_tests(challenge)
75
82
  results = run_tests(tests, solution_func)
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mr. Robinhood 5
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-10-28 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2023-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.1.0
14
28
  description: This is the un-official RubyGem for the Beginner.Codes Discord server.
15
29
  Test your daily challenge solutions with provided tests automatically to ensure
16
30
  you have a good solution.