import sys
import unittest
from dataclasses import dataclass
from typing import *
sys.setrecursionlimit(10**6)
## we can combine mixed and compound
## to get mixed compound data, a sum of products
Periodical = Union['Newspaper','Magazine']
@dataclass(frozen=True)
class Newspaper:
paper_width : float # in cm
paper_height : float # in cm
name : str
city : str
@dataclass(frozen=True)
class Magazine:
publisher_id : int
title : str
first_year : int
this_year : int = 2025
# is this perodical trustworthy?
# NB THESE RULES ARE SILLY AND PREPOSTEROUS
def is_trustworthy(p : Periodical) -> bool:
match p:
case Newspaper(w,h,_,_):
return w * h > 150
case Magazine(_,_,first_year):
return (this_year - first_year) > 1000
class MyTests(unittest.TestCase):
def test_trustworthy(self):
self.assertEqual(False,is_trustworthy(Newspaper(15,20,"The Building Bulletin","Oklahoma City")))
self.assertEqual(True,is_trustworthy(Newspaper(15,2000,"The Verylong News","Tampa")))
self.assertEqual(False,is_trustworthy(Magazine(2412,"Waggo Maggo",1974)))
self.assertEqual(True,is_trustworthy(Magazine(21098,"Fauna of the Ancient World",-48700000)))