Skip to content

Instantly share code, notes, and snippets.

@miyohide
Last active June 16, 2019 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyohide/bf80c3eadcd37401d2a65e66f8150b56 to your computer and use it in GitHub Desktop.
Save miyohide/bf80c3eadcd37401d2a65e66f8150b56 to your computer and use it in GitHub Desktop.
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