Esempio n. 1
0
import json
from jsonCounter import JsonCounter
from jsonCounter import JsonCounterNoRed

with open("input.json") as json_file:
    data = json.load(json_file)

# part 1 - count all the numbers in the file
print(JsonCounter.getTotalForObject(data))
# part 2 - count all the numbers except those in objects that contain the value "red"
print(JsonCounterNoRed.getTotalForObjectNoRed(data))
Esempio n. 2
0
 def test_no_red(self):
     self.assertEqual(6,JsonCounterNoRed.getTotalForObjectNoRed([1,2,3]))
     self.assertEqual(4,JsonCounterNoRed.getTotalForObject([1,{"c":"red", "b": 2},3]))
     self.assertEqual(0,JsonCounterNoRed.getTotalForObjectNoRed({"d":"red","e":[1,2,3,4],"f":5}))
     self.assertEqual(6,JsonCounterNoRed.getTotalForObjectNoRed([1,"red",5]))