from PIL import Image import skykit from tests.helpers import count_colour LIT, DARK, BG = (255, 255, 255), (40, 40, 40), (0, 0, 0) def moon(pct, waxing): img = Image.new("RGB", (40, 40), BG) skykit.moon_disc(img, 20, 20, 16, pct, waxing, lit=LIT, dark=DARK) return img def lit(img, box=None): return count_colour(img, LIT, box) def test_waxing_moon_is_lit_on_the_right_waning_on_the_left(): waxing, waning = moon(50, True), moon(50, False) assert lit(waxing, (20, 0, 40, 40)) > 10 * max(1, lit(waxing, (0, 0, 20, 40))) assert lit(waning, (0, 0, 20, 40)) > 10 * max(1, lit(waning, (20, 0, 40, 40))) def test_lit_area_grows_with_illumination(): areas = [lit(moon(pct, True)) for pct in (0, 10, 50, 90, 100)] assert areas == sorted(areas) assert areas[0] == 0 assert areas[-1] > 0.9 * 3.14 * 16 * 16