-
-
Save miyohide/bf80c3eadcd37401d2a65e66f8150b56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minitest/autorun" | |
require "json" | |
def solve(src) | |
src_i = src.to_i(16) | |
out = [] | |
1.upto src_i do |i| | |
if (src_i & i ) == i | |
out << i | |
end | |
end | |
if out.length > 15 | |
out[0..12].join(",") + ",...," + out[-2].to_s + "," + out[-1].to_s | |
else | |
out.join(",") | |
end | |
end | |
if ! ARGV[0] || ! File.exist?( ARGV[0] ) | |
raise "you should specify json file as ARGV[0]" | |
end | |
class TestYokohamaRb103 < Minitest::Test | |
json_string = File.open( ARGV[0], &:read ) | |
data = JSON.parse( json_string, symbolize_names:true ) | |
data[:test_data].each do | number:, src:, expected: | | |
define_method( :"test_#{number}" ) do | |
actual = solve(src) | |
assert_equal( expected, actual ) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment