beginner.codes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +20 -0
- data/lib/challenges.rb +77 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e73ed44153a46af785e54a54c6d9148ffafff640df37eaae0b5d5c6f2845e6c
|
4
|
+
data.tar.gz: c4fff25ea579374a11b78b5ce1d1016d45347e8d73a2de64e7703c840d12b56b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d4d41a32a3bcc57a557af7428a17736bf3be2841bd4c681458538494d263bc5f6812d1691ed9cf50296dba01b51cfedf021fb76ed4847d64543e4bd92a7c2f9
|
7
|
+
data.tar.gz: c00527bbee429d00fdfd0a1783fcaa09a09b1cf0ef17765c36bde9a77ef43bbb83fb28bb449d65a1cee71e053a397e51a021107b6d287e76ba7803dc899daa72
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Beginner.Codes Ruby Gem
|
2
|
+
|
3
|
+
This is the un-official Ruby Gem for the Beginner.Codes Discord server.
|
4
|
+
|
5
|
+
## Running Challenge Tests
|
6
|
+
|
7
|
+
- Install the package: `gem install beginner.codes`
|
8
|
+
- Import the test runner: `include 'beginner.codes'`
|
9
|
+
- Run the tests, passing in the challenge number and your solution function: `test(458, n_differences)`
|
10
|
+
```ruby
|
11
|
+
include 'beginner.codes'
|
12
|
+
|
13
|
+
def n_differences(nums)
|
14
|
+
nil
|
15
|
+
end # Your code goes here!!!
|
16
|
+
|
17
|
+
|
18
|
+
test(458, n_differences)
|
19
|
+
```
|
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.
|
data/lib/challenges.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
# this gets imported to your file
|
8
|
+
|
9
|
+
module Status
|
10
|
+
SUCCESS = 1
|
11
|
+
FAILED = 0
|
12
|
+
EXCEPTION = -1
|
13
|
+
end
|
14
|
+
|
15
|
+
# captures the result of the test
|
16
|
+
class Result
|
17
|
+
attr_accessor :got, :status
|
18
|
+
attr_reader :index, :expected
|
19
|
+
|
20
|
+
def initialize(index, expected, got = nil, status = Status::SUCCESS)
|
21
|
+
@index = index
|
22
|
+
@expected = expected
|
23
|
+
@got = got
|
24
|
+
@status = status
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def get_tests(challenge)
|
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
|
+
response = Net::HTTP.get_response(uri)
|
33
|
+
raise "Challenge #{challenge} was not found" unless response.is_a?(Net::HTTPSuccess)
|
34
|
+
|
35
|
+
JSON.parse(response.body)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_tests(tests, solution_func)
|
40
|
+
results = []
|
41
|
+
tests.each_with_index do |test_case, index|
|
42
|
+
result = Result.new(index, test_case['return'])
|
43
|
+
begin
|
44
|
+
result.got = send(solution_func, *test_case['args'])
|
45
|
+
rescue StandardError => e
|
46
|
+
result.status = Status::EXCEPTION
|
47
|
+
result.got = e
|
48
|
+
else
|
49
|
+
result.status = Status::FAILED unless result.got.equal?(test_case['return'])
|
50
|
+
end
|
51
|
+
results << result
|
52
|
+
end
|
53
|
+
results
|
54
|
+
end
|
55
|
+
|
56
|
+
def show_results(challenge, results, total_tests)
|
57
|
+
failures = 0
|
58
|
+
results.each do |result|
|
59
|
+
if result.status.equal?(Status::FAILED)
|
60
|
+
puts "Test #{result.index} failed: Expected #{result.expected}, got #{result.got}."
|
61
|
+
failures += 1
|
62
|
+
elsif result.status.equal?(Status::EXCEPTION)
|
63
|
+
puts "Test #{result.index} failed: #{result.got}"
|
64
|
+
failures += 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
puts ' ' if failures
|
68
|
+
puts "---- Challenge #{challenge} Results ----"
|
69
|
+
puts "#{total_tests - failures} passed, #{failures} failed"
|
70
|
+
puts "\n**** Great job!!! ****" if failures.zero?
|
71
|
+
end
|
72
|
+
|
73
|
+
def test(challenge, solution_func)
|
74
|
+
tests = get_tests(challenge)
|
75
|
+
results = run_tests(tests, solution_func)
|
76
|
+
show_results(challenge, results, tests.size)
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beginner.codes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mr. Robinhood 5
|
8
|
+
- Zech Zimmerman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This is the un-official RubyGem for the Beginner.Codes Discord server.
|
15
|
+
email: mrrobinhood5@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README
|
21
|
+
- lib/challenges.rb
|
22
|
+
homepage:
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.4.10
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Test your challenge solutions.
|
45
|
+
test_files: []
|