forked from exercism/problem-specifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.rb
19 lines (14 loc) · 751 Bytes
/
verify.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'json'
require_relative '../../verify'
# Wow, this verifies the description too!
ALLERGENS = File.readlines(File.join(__dir__, 'description.md')).grep(/^\* [a-z]+ \([\d]+\)$/).map { |line|
[line[/[a-z]+/], line[/\d+/].to_i]
}.to_h.freeze
json = JSON.parse(File.read(File.join(__dir__, 'canonical-data.json')))
raise "There should be exactly two cases, not #{json['cases'].size}" if json['cases'].size != 2
verify(json['cases'][0]['cases'], property: 'allergicTo', accept: ->(c, ans) { c['expected'].all? { |e| ans[e['substance']] == e['result'] } }) { |i, _|
ALLERGENS.transform_values { |v| v & i['score'] != 0 }
}
verify(json['cases'][1]['cases'], property: 'list') { |i, _|
ALLERGENS.select { |_, v| i['score'] & v != 0 }.keys
}