class Book: # a structure that represents a book """This class represents a book-type publication. A book has the following attributes: title, author, publisher, location and year.""" def __init__(self,title,author,publisher,location,year): #to instantiate books self.title = title self.author = author self.publisher = publisher self.location = location self.year = year #function for a book to cite itself in APA format def citeApa(self): return "{} ({}). {}. {}: {}.".format(self.author,self.year,self.title,self.location,self.publisher) #function for a book to cite itself in MLA format def citeMla(self): return "{}. {}. {}: {}, {}.".format(self.author,self.title,self.location,self.publisher,self.year) class Article: # a structure that represents a journal article """This class represents a journal article-type publication. A journal article has the following attributes: title, author, name of journal, volume number, issue number and year. """ def __init__(self,title,author,journalName,volume,issue,year): self.title = title self.author = author self.journalName = journalName self.volume = volume self.issue = issue self.year = year #function for an article to cite itself in APA format def citeApa(self): return "{} ({}). {}. {}, {}({}).".format(self.author,self.year,self.title,self.journalName,self.volume,self.issue) #function for an article to cite itself in MLA format def citeMla(self): return "{}. \"{}.\" {} {}.{} ({}).".format(self.author,self.title,self.journalName,self.volume,self.issue,self.year) class Webpage: # a structure that represents a web page """This class represents a webpage-type publication. A web page has the following attributes: title, URL and the date of download. """ def __init__(self,title,url,date): self.title = title self.url = url self.date = date #function for a web page to cite itself in APA format def citeApa(self): return "{}. Retrieved {}, from {}.".format(self.title,self.date,self.url) #function for a web page to cite itself in MLA format def citeMla(self): return "\"{}.\" Web. {} <{}>.".format(self.title,self.date,self.url) #create an instance that represents the famous book "Midnight's Children" rushdie = Book("Midnight's Children","Salman Rushdie","Jonathan Cape","London",1980) #create an instance that represents a journal article by Turing turing = Article("Computing machinery and intelligence","A. M. Turing", "Mind", 59, 236, 1950) #create an instance that represents a web page ccis = Webpage("CCIS at Northeastern University","https://www.ccis.northeastern.edu/","10th August 2018") ########################## Tests ###################### #tests for publications defined in an OO manner import unittest class OOPublicationTests(unittest.TestCase): def setUp(self): #create an instance that represents the famous book "Midnight's Children" rushdie = Book("Midnight's Children","Salman Rushdie","Jonathan Cape","London",1980) #create an instance that represents a journal article by Turing turing = Article("Computing machinery and intelligence","A. M. Turing", "Mind", 59, 236, 1950) #create an instance that represents a web page ccis = Webpage("CCIS at Northeastern University","https://www.ccis.northeastern.edu/","10th August 2018") def test_citeApa(self): self.assertEquals("Salman Rushdie (1980). Midnight's Children. London: Jonathan Cape.",rushdie.citeApa()) self.assertEquals("A. M. Turing (1950). Computing machinery and intelligence. Mind, 59(236).",turing.citeApa()) self.assertEquals("CCIS at Northeastern University. Retrieved 10th August 2018, from https://www.ccis.northeastern.edu/.",ccis.citeApa()) def test_citeMla(self): self.assertEquals("Salman Rushdie. Midnight's Children. London: Jonathan Cape, 1980.",rushdie.citeMla()) self.assertEquals("A. M. Turing. \"Computing machinery and intelligence.\" Mind 59.236 (1950).",turing.citeMla()) self.assertEquals("\"CCIS at Northeastern University.\" Web. 10th August 2018 .",ccis.citeMla()) suite = unittest.TestLoader().loadTestsFromTestCase(OOPublicationTests) unittest.TextTestRunner(verbosity=2).run(suite)