class TestRandomC: """Define a julia set with a random c seed value, test interface""" def setup(self): """Setup fixture is run before every test method separately""" self.c = rand_range() self.n = randint(2,100) self.j = JuliaSet(self.c, self.n) def test_c_value(self): """Test that c is an attribute""" assert self.j.c == self.c def test_n_value(self): """Test that n is an attribute""" assert self.j.n == self.n def test_juliamap(self): """Test that juliamap is implemented properly""" z = rand_range() print "z = ", z print "z**2 = ", z**2 zcorrect = z**2 + self.c print "z**2 + c = ", zcorrect znew = self.j.juliamap(z) print "juliamap(z) = ", znew assert znew == zcorrect def test_set_spacing(self): """Test that changing spacing works""" print "Test original spacing _d = 0.001" assert self.j._d == 0.001 print "Test new spacing of _d = 0.1" self.j.set_spacing(0.1) print "_d = ", self.j._d assert self.j._d == 0.1 print "Test that complex plane is regenerated" print "len(_complexplane) = ", self.j._complexplane.size #print "len(_complexplane) = ", len(self.j._complexplane) print "int(4.0 / 0.1)**2 = ", int(4.0 / 0.1)**2 assert self.j._complexplane.size == int(4.0 / 0.1)**2 #assert len(self.j._complexplane) == int(4.0 / 0.1)**2 def test_generate(self): """Test that generating the julia set works""" self.j.set_spacing(0.1) self.j.generate() print "Test that j.set exists, and is of the same length as j._complexplane" assert (len(self.j.set) == len(self.j._complexplane))
def main(argv): date_img = False tweet_img = True img_path = "saves" if len(argv) - 1 > 0: i = 1 while i < len(argv): if argv[i] == "--date_img": date_img = True elif argv[i] == "--no_tweet": tweet_img = False elif argv[i] == "--path": if i != len(argv) - 1: i += 1 img_path = argv[i] else: print("Unknown parameter: " + argv[i]) exit() i += 1 ca = uniform(C_LIMIT[0], C_LIMIT[1]) cb = uniform(C_LIMIT[0], C_LIMIT[1]) set = JuliaSet(ca, cb, WIDTH, HEIGHT, COLOR_MODES[randint(0, len(COLOR_MODES) - 1)], date_img) set.genImage(ITERATIONS, ZOOM) set.saveImage(img_path) if tweet_img: keys = getkeys(tweet_img) auth = tweepy.OAuthHandler(keys[0], keys[1]) auth.set_access_token(keys[2], keys[3]) api = tweepy.API(auth) try: status = f"Julia set generated on {set.date_stamp} at {set.time_stamp} {tzname[0]}\nIterations: {ITERATIONS}\nColoring mode: \"{set.c_mode}\"\nc = {ca} + {cb}i" api.update_with_media(f"{img_path}/{set.file_name}", status) print("Successfully tweeted.") except tweepy.TweepError as e: print(f'Tweepy error:\n {e.reason}')
def setup(self): """Setup fixture is run before every test method separately""" self.c = rand_range() self.n = randint(2,100) self.j = JuliaSet(self.c, self.n)