"""Check the PISA 2022 score differences against the accompanying CSV."""

import csv
from pathlib import Path


def main():
    data_path = Path(__file__).with_name("data-sample.csv")
    with data_path.open(encoding="utf-8", newline="") as source:
        for row in csv.DictReader(source):
            domain = row["domain"]
            japan_mean = int(row["japan_mean"])
            oecd_mean = int(row["oecd_mean"])
            difference = japan_mean - oecd_mean
            if difference != int(row["difference_score_points"]):
                raise ValueError(f"{domain}: the recorded difference does not match the means.")
            print(f"{domain}: Japan {japan_mean}, OECD average {oecd_mean}, "
                  f"difference {difference:+d} score points")


if __name__ == "__main__":
    main()
