def calc(o,a,b): if o==0: print(add.add(a,b)) return add.add(a,b) if o==1: print(mul.mul(a,b)) return mul.mul(a,b)
def test_any_number_of_matrixes(self): m1 = [[6, 6], [3, 1]] m2 = [[1, 2], [3, 4]] m3 = [[2, 1], [3, 4]] m4 = [[9, 9], [9, 9]] m5 = [[31, 32], [27, 24]] self.assertEqual(add(m1, m2, m3), m4) self.assertEqual(add(m2, m3, m1, m1, m2, m4, m1), m5)
def test_input_unchanged(self): m1 = [[6, 6], [3, 1]] m2 = [[1, 2], [3, 4]] m1_original = deepcopy(m1) m2_original = deepcopy(m2) add(m1, m2) self.assertEqual(m1, m1_original) self.assertEqual(m2, m2_original)
def testInit(self): elem1 = 1 elem2 = 3 additionResult = 4 wrongAdditionResult = 5 computeResult = add.add(elem1, elem2).get() self.assertEqual(computeResult, additionResult)
def test_different_matrix_size(self): m1 = [[6, 6], [3, 1]] m2 = [[1, 2], [3, 4], [5, 6]] m3 = [[6, 6], [3, 1, 2]] with self.assertRaises(ValueError): add(m1, m2) with self.assertRaises(ValueError): add(m1, m3) with self.assertRaises(ValueError): add(m1, m1, m1, m3, m1, m1) with self.assertRaises(ValueError): add(m1, m1, m1, m2, m1, m1)
def word_count(): result = wikipedia.page("New York City") content = result.summary t_config = TableConfig() env = ExecutionEnvironment.get_execution_environment() t_env = BatchTableEnvironment.create(env, t_config) print(add.add(10,5)) print("Word Count"); # register Results table in table environment tmp_dir = tempfile.gettempdir() result_path = tmp_dir + '/result' if os.path.exists(result_path): try: if os.path.isfile(result_path): os.remove(result_path) else: shutil.rmtree(result_path) except OSError as e: logging.error("Error removing directory: %s - %s.", e.filename, e.strerror) logging.info("Results directory: %s", result_path) #sink_ddl = """ # create table Results( # word VARCHAR, # `count` BIGINT # ) with ( # 'connector.type' = 'filesystem', # 'format.type' = 'csv', # 'connector.path' = '{}' # ) # """.format(result_path) t_env.connect(FileSystem().path('/tmp/output')) \ .with_format(OldCsv() .field_delimiter('\t') .field('word', DataTypes.STRING()) .field('count', DataTypes.BIGINT())) \ .with_schema(Schema() .field('word', DataTypes.STRING()) .field('count', DataTypes.BIGINT())) \ .create_temporary_table('Results') #t_env.sql_update(sink_ddl) elements = [(word, 1) for word in content.split(" ")] t_env.from_elements(elements, ["word", "count"]) \ .group_by("word") \ .select("word, count(1) as count") \ .insert_into("Results") t_env.execute("word_count")
def calc(operation, a, b): if operation == 0: return add.add(a, b) if operation == 1: return mul.mul(a, b)
def test_single_items(self): self.assertEqual(add([[5]], [[-2]]), [[3]])
def test_two_by_three_matrixes(self): m1 = [[1, 2, 3], [4, 5, 6]] m2 = [[-1, -2, -3], [-4, -5, -6]] m3 = [[0, 0, 0], [0, 0, 0]] self.assertEqual(add(m1, m2), m3)
def test_two_by_two_matrixes(self): m1 = [[6, 6], [3, 1]] m2 = [[1, 2], [3, 4]] m3 = [[7, 8], [6, 5]] self.assertEqual(add(m1, m2), m3)
def test_only_accepts_a_number(self): result = add.add(["ten"]) self.assertEqual("numbers only", result)
def test_adds_a_number_to_a_list(self): list = [10, 2, 3] result = add.add([4,5,6]) self.assertEqual(10, 2, 3, 4, 5, 6, result)
def test_add(): value = add(1) assert value == 13