def testFn_Zip(self): """Test the wdl built-in functional equivalent of 'zip()'.""" left_array = [1, 2, 3] right_array = ['a', 'b', 'c'] zipped = wdl_zip(left_array, right_array) expected_results = [WDLPair(1, 'a'), WDLPair(2, 'b'), WDLPair(3, 'c')] self.assertEqual(zipped, expected_results) # input with different size should fail. self.assertRaises(WDLRuntimeError, wdl_zip, [1, 2, 3], ['a', 'b'])
def testFn_WriteJson(self): """Test the wdl built-in functional equivalent of 'write_json()'.""" json_obj = { 'str': 'some string', 'num': 3.14, 'bool': True, 'null': None, 'arr': ['test'] } json_arr = ['1', '2'] json_num = 3.14 json_str = 'test string' json_bool = False json_null = None # Pair[Int, Pair[Int, Pair[Int, Pair[Int, Int]]]] json_pairs = WDLPair(1, WDLPair(2, WDLPair(3, WDLPair(4, 5)))) path = write_json(json_obj, temp_dir=self.output_dir) self._check_output( path, '{"str":"some string","num":3.14,"bool":true,"null":null,"arr":["test"]}' ) path = write_json(json_arr, temp_dir=self.output_dir) self._check_output(path, '["1","2"]') path = write_json(json_num, temp_dir=self.output_dir) self._check_output(path, '3.14') path = write_json(json_str, temp_dir=self.output_dir) self._check_output(path, '"test string"') path = write_json(json_bool, temp_dir=self.output_dir) self._check_output(path, 'false') path = write_json(json_null, temp_dir=self.output_dir) self._check_output(path, 'null') path = write_json(json_pairs, temp_dir=self.output_dir) self._check_output( path, '{"left":1,"right":{"left":2,"right":{"left":3,"right":{"left":4,"right":5}}}}' )
def testFn_Cross(self): """Test the wdl built-in functional equivalent of 'cross()'.""" left_array = [1, 2, 3] right_array = ['a', 'b'] crossed = cross(left_array, right_array) expected_results = [ WDLPair(1, 'a'), WDLPair(1, 'b'), WDLPair(2, 'a'), WDLPair(2, 'b'), WDLPair(3, 'a'), WDLPair(3, 'b') ] self.assertEqual(crossed, expected_results)