2021-10-05 10:05:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
>>> import random
|
|
|
|
>>> import math
|
2021-10-12 13:03:10 +00:00
|
|
|
>>> import os
|
2021-10-05 11:22:14 +00:00
|
|
|
>>> import pickle
|
2021-10-12 16:29:28 +00:00
|
|
|
>>> import socket
|
|
|
|
>>> def guard(*args, **kwargs):
|
|
|
|
... raise Exception("No internet connection!")
|
2021-10-05 10:05:33 +00:00
|
|
|
>>> from samila import GenerativeImage, Projection
|
2021-10-06 20:24:03 +00:00
|
|
|
>>> from samila.functions import is_same_data
|
2021-10-05 10:05:33 +00:00
|
|
|
>>> import pickle
|
|
|
|
>>> def f1(x,y):
|
|
|
|
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
|
|
|
|
... return result
|
|
|
|
>>> def f2(x,y):
|
|
|
|
... result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
|
|
|
|
... return result
|
|
|
|
>>> g = GenerativeImage(f1,f2)
|
|
|
|
>>> g.function1 == f1
|
|
|
|
True
|
|
|
|
>>> g.function2 == f2
|
|
|
|
True
|
|
|
|
>>> g.fig
|
|
|
|
>>> g.generate()
|
|
|
|
>>> isinstance(g.data1, list)
|
|
|
|
True
|
|
|
|
>>> isinstance(g.data2, list)
|
|
|
|
True
|
|
|
|
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
|
|
|
|
>>> g.seed
|
|
|
|
10
|
2021-10-05 11:22:14 +00:00
|
|
|
>>> with open("test/test1_1_d1.pkl", "rb") as fp:
|
|
|
|
... temp_data = pickle.load(fp)
|
2021-10-06 20:24:03 +00:00
|
|
|
>>> is_same_data(g.data1, temp_data)
|
2021-10-05 10:05:33 +00:00
|
|
|
True
|
2021-10-05 11:22:14 +00:00
|
|
|
>>> with open("test/test1_1_d2.pkl", "rb") as fp:
|
|
|
|
... temp_data = pickle.load(fp)
|
2021-10-06 20:24:03 +00:00
|
|
|
>>> is_same_data(g.data2, temp_data)
|
2021-10-05 10:05:33 +00:00
|
|
|
True
|
|
|
|
>>> g.plot()
|
2021-10-12 13:03:10 +00:00
|
|
|
>>> result = g.save_image("test.png")
|
|
|
|
>>> result["status"]
|
|
|
|
True
|
|
|
|
>>> result["message"]
|
|
|
|
'Everything seems good.'
|
2021-10-05 10:05:33 +00:00
|
|
|
>>> g.plot(color='red')
|
|
|
|
>>> g.plot(color='red', bgcolor='black')
|
2021-10-12 13:03:10 +00:00
|
|
|
>>> result = g.save_image("test2.png")
|
|
|
|
>>> result["status"]
|
|
|
|
True
|
|
|
|
>>> result["message"]
|
|
|
|
'Everything seems good.'
|
2021-10-05 10:05:33 +00:00
|
|
|
>>> from samila import GenerativeImage, Projection
|
|
|
|
>>> g.plot(projection=Projection.POLAR, color='red', bgcolor='black')
|
|
|
|
>>> g.plot(projection=Projection.POLAR, color=(.1, .2, .8))
|
|
|
|
>>> g.plot(bgcolor=(.1, .2, .8), spot_size=0.1)
|
|
|
|
>>> g.plot(size=(20, 20))
|
|
|
|
>>> result = g.nft_storage(api_key="")
|
|
|
|
>>> result['status']
|
|
|
|
False
|
|
|
|
>>> result['message']
|
|
|
|
'API Key is missing, make sure the `Authorization` header has a value in the following format `Bearer {api key}`.'
|
2021-10-11 22:12:50 +00:00
|
|
|
>>> g = GenerativeImage(f1,f2)
|
|
|
|
>>> result = g.nft_storage(api_key="")
|
|
|
|
>>> result["status"]
|
|
|
|
False
|
|
|
|
>>> result["message"]
|
|
|
|
'No figure was found. First run `generate` and `plot` methods.'
|
2021-10-12 12:53:09 +00:00
|
|
|
>>> result = g.save_image(file_adr="")
|
|
|
|
>>> result["status"]
|
|
|
|
False
|
|
|
|
>>> result["message"]
|
|
|
|
'No figure was found. First run `generate` and `plot` methods.'
|
2021-10-12 16:18:18 +00:00
|
|
|
>>> g.fig = 2
|
|
|
|
>>> result = g.nft_storage(api_key="")
|
|
|
|
>>> result['status']
|
|
|
|
False
|
|
|
|
>>> result = g.save_image(file_adr="")
|
|
|
|
>>> result["status"]
|
|
|
|
False
|
2021-10-12 16:29:28 +00:00
|
|
|
>>> socket.socket = guard
|
|
|
|
>>> g.generate()
|
|
|
|
>>> g.plot()
|
|
|
|
>>> result = g.nft_storage("")
|
|
|
|
>>> result["status"]
|
|
|
|
False
|
|
|
|
>>> result["message"]
|
|
|
|
'No internet connection!'
|
2021-10-12 13:03:10 +00:00
|
|
|
>>> os.remove("test.png")
|
|
|
|
>>> os.remove("test2.png")
|
2021-10-05 10:05:33 +00:00
|
|
|
"""
|