#] #] ********************* #] "$d_Qroot""6_test examples.txt" 05Oct2021 initial taken from "0_QNial summary.txt" plus new examples #**************************** # Table of contents, generated with : # $ grep "^#]" "$d_Qroot""6_test examples.txt" | sed 's/^#\]/ /' # +-----+ 1 argument tests - really simple test of an operator with 1 argument +-----+ 2 argument tests - somewhat simple test of an operator atomA_restructSameAs_ary_test IS - compare ary structures (top-most level) using different transformers +-----+ [path, dir] optr tests - These require the use of FIXED (unchanging) test [input, standard result] [path_exist checks, backups] are a key parts of this!! stable [test, std] files provides consistent processing AND compares [std, result] files Linux "diff" usage examples :[str_replaceIn_path_output, path_replace_wordL_test_output] pZarchive_restore_test IS OP - restore most recent path_backupDatedTo_zArchive of a file, path_backupDatedTo_zArchive current version of file, retain the backup pathL_strL_grepOptions_linesTo_pout_test IS - search strL in pathL, return lines that hit [construct, run] a grepExpr, assumes that ALL pathL are valid files! (check before calling!) the number of strs is limited in [find, grep, sed] or the expressions exceed maxLength= ?? str_replaceIn_path_output IS OP i_test pinn - common optr to execute & ouput diff to log file str_replaceIn_path_test IS OP - test pinn link fixes, write diff to log file path_replace_wordL_test_output IS OP i_test pstd wordOldNew - uses common template to execute & ouput diff to log file, for tests flag_backup is false pathL_replace_wordL_test IS OP - test pinn link fixes, write diff to log file +-----+ TRANSFORMER tests - both [formal, IS OP with opPhr] ary1_transStr_isSameStructAs_ary2_test IS - use different transformers with the same test data for comparison of ary structures 08********08 #] +-----+ #] 1 argument tests - really simple test of an operator with 1 argument # 06Sep2021 initial +-----+ # loaddefs link d_Qtest 'strings/strings- tests.ndf' IF flag_debug THEN write 'loading strL_eachQuoted_strOut_testStrL' ; ENDIF ; #] strL_eachQuoted_strOut_testStrL := - convert strL to a single string of [quote, space]d subStrs # www.BillHowell.ca 24Jun2021 initial # 05Nov2021 cut to dataBone strL_eachQuoted_strOut_testStrL := "test_simple 1 "strL_eachQuoted_strOut (link d_Qtest 'strings/z_Archive/') ( "t01 ('bear' 'bull' 'pig' 'wolf' ) (' "bear" "bull" "pig" "wolf" ' ) 'comments?' "t02 ('bear' 'bull' 'pig' '' ) (' "bear" "bull" "pig" "" ' ) 'comments?' "t03 ('' 'bull' '' 'wolf' ) (' "" "bull" "" "wolf" ' ) 'comments?' "t04 ('bear' 'bull' '"pig"' 'wolf' ) (' "bear" "bull" ""pig"" "wolf" ' ) 'comments?' "t05 ('bear' null '"pig' 'wolf"' ) (' "bear" "" ""pig" "wolf"" ' ) 'comments?' "t06 ('bear' null 'pig' null ) (' "bear" "" "pig" "" ' ) 'comments?' ) ; 08********08 #] +-----+ #] 2 argument tests - somewhat simple test of an operator +-----+ # loaddefs link d_Qtest 'strings/strings- tests.ndf' IF flag_debug THEN write 'loading str_subStrs_getLenMatches_subStrPairs_test' ; ENDIF ; #] str_subStrs_getLenMatches_subStrPairs_test := - return (str = link subStrPairs) # 20Jun2021 initial str_subStrs_getLenMatches_subStrPairs_test := "test_simple 2 "str_subStrs_getLenMatches_subStrPairs (link d_Qtest 'strings/z_Archive/') ( "t01 'giraffe' ('gi' 'aff' 'affe' 'raffe' 'gir') ('gi' 'raffe' 'gir' 'affe') 'comment?' "t02 'elephant' ('e' 'hant' 'a') '' 'comment?' "t03 'banana' ('anana' 'ban' 'banana' 'b' '' 'anana' 'ban' 'ana') ('ban' 'ana') ('b' 'anana') 'comment?' "t04 '' ('gi' 'aff' 'affe' 'raf' 'a' 'gir') '' 'comment?' "t05 'covid-19' '' '' 'comment?' "t06 'hydroxychloroquinine' ['hydroxychloroquinine'] '' 'comment?' ) ; 08********08 #] +-----+ #] 3 argument tests - somewhat simple test of an operator +-----+ # loaddefs link d_Qtest 'strings/strings- tests.ndf' IF flag_debug THEN write 'loading str_splitLftRgtTo_midIndxs_StrList_test' ; ENDIF ; #] str_splitLftRgtTo_midIndxs_StrList_test := - splits S2 at each point that S1 occurs, S1 separate # 06May2020 based on 'strings/strings- tests.ndf' str_splitLftRgtTo_midIndxs_StrList_test := "test_simple 3 "str_splitLftRgtTo_midIndxs_StrList (link d_Qtest 'strings/z_Archive/') ( "t01 '' '[#=; ' ' ;=#]' ((solitary 2) ('') ) 'comment?' "t02 '
Stephen Puetz 2011 "Universal Wave Series"
' '[#=; ' ' ;=#]' ((solitary 2) ('
Stephen Puetz 2011 "Universal Wave Series"
') ) 'comment?' "t03 'This topic fits well into my theme "Lies, Damned Lies, and Scientists".' '[#=; ' ' ;=#]' ((solitary 2) ('This topic fits well into my theme "Lies, Damned Lies, and Scientists".') ) 'comment?' "t04 'This topic fits well into my theme "Lies, Damned Lies, and Scientists".' 'This topic fits well into my theme ' '"' null 'Lies, Damned Lies, and Scientists' '"' '.') ) 'comment?' "t05 '' '') ) 'comment?' ) ; 08********08 #] +-----+ #] [path, dir] optr tests - These require the use of FIXED (unchanging) test [input, standard result] #] [path_exist checks, backups] are a key parts of this!! #] stable [test, std] files provides consistent processing AND compares [std, result] files #] Linux "diff" usage examples :[str_replaceIn_path_output, path_replace_wordL_test_output] +-----+ # loaddefs link d_Qtest 'fileops/file_ops- test.ndf' IF flag_debug THEN write 'loading pthL_resultL_faultL_shortenTo_Codes' ; ENDIF ; #] pthL_resultL_faultL_shortenTo_Codes IS OP pthL resultL faultL - for fairly general use #] [pthL, resultL] for faults are converted to codes for brevity in the output #] of course, a resultCode of l (true) is kept the same #] 25Oct2021 used for [pth_typ_exists, pth_backupDatedTo_zArchive]_test IF flag_break THEN BREAK ; ENDIF ; pthL_resultL_faultL_shortenTo_Codes IS OP pthL resultL faultL { LOCAL codedFaultNumberL codedFaultStrL codedResultL pthShortL i indxChgL tell_n_rows ; NONLOCAL d_Qndfs d_Qtest ; % ; pthShortL := pthL EACHLEFT str_remove_subStr (link d_Qtest 'fileops/') ; % ; codedFaultNumberL := '(' EACHRIGHT link (EACH string (tell (gage shape faultL))) EACHLEFT link ')' ; codedFaultStrL := codedFaultNumberL EACHBOTH link (' ' EACHRIGHT link (EACH string faultL)) ; % ; tell_n_rows := tell (gage shape pthL) ; codedResultL := resultL ; FOR i WITH tell_n_rows DO indxChgL := (faultL@i EACHRIGHT in resultL) sublist tell_n_rows ; codedResultL#(indxChgL) := (gage shape indxChgL) reshape [codedFaultNumberL@i] ; ENDFOR ; pthShortL codedResultL codedFaultNumberL codedFaultStrL } +-----+ # loaddefs link d_Qtest 'fileops/file_ops- test.ndf' IF flag_debug THEN write 'loading pth_typ_exists_test' ; ENDIF ; #] pth_typ_exists_test IS OP p_log - res ipsa loquitor, types = [p_ = path, d_ = dir]cart[old, new] # ?date <2020? initial, 26Oct2021 finish major revamp including test # 26Oct2021 revamped pth_typ_exists : many if not most uses will not work with tighter definitions pth_typ_exists_test IS OP p_log { LOCAL optr d_testy d_exists d_empty d_noExist p_exists p_noExist p_empty inputs n_cols n_rows testNumL dat1L dat2L stdResultL commentL resultLL pthShortL codedResultL OKL test_tbl ; NONLOCAL d_Qtest ; % ; optr := "pth_typ_exists ; % ; d_testy := link d_Qtest 'fileops/test input files/' ; d_exists := link d_testy ; d_empty := link d_Qtest 'fileops/dir empty tests (dont add files)/' ; d_noExist := link d_testy 'noExist/' ; % ; p_exists := link d_testy 'test- strings.ndf' ; p_noExist := link d_testy 'strngs.ndf' ; p_empty := link d_testy 'test- empty file.txt' ; % ; % test numbers "txx are in base 12, matching the length of each test series ; inputs := "01_d_exists d_exists "d_old null 'should be OK - dir exists' "02_d_exists d_exists "d_new '6 ' 'should fail - 6 cannot overwrite dir' "03_d_exists d_exists "p_old '2 ' 'should fail - 2 dir is not a path' "04_d_exists d_exists "p_new '2 6 ' 'should fail - 2 dir is not a path, 6 cannot overwrite dir' "01_d_empty d_empty "d_old null 'should be OK - dir exists though empty' "02_d_empty d_empty "d_new '6 ' 'should fail - 6 cannot overwrite dir' "03_d_empty d_empty "p_old '2 ' 'should fail - 2 dir is not a path' "04_d_empty d_empty "p_new '2 6 ' 'should fail - 2 dir is not a path, 6 cannot overwrite dir' "01_d_noExist d_noExist "d_old '1 ' 'should fail - 1 [dir,path] not found' "02_d_noExist d_noExist "d_new '4 ' 'should fail - 4 containing dir noExist, so can"t add new subDir to it' "03_d_noExist d_noExist "p_old '1 2 ' 'should fail - 1 [dir,path] not found, 2 dir is not a path' "04_d_noExist d_noExist "p_new '2 5 ' 'should fail - 2 dir is not a path, 5 "p_new containing dir noExist' "01_p_exists p_exists "d_old '3 ' 'should fail - 3 pth is not a dir' "02_p_exists p_exists "d_new '3 6 ' 'should fail - 3 pth is not a dir, 6 cannot overwrite dir' "03_p_exists p_exists "p_old null 'should be OK - pth exists' "04_p_exists p_exists "p_new '7 ' 'should fail - pth exists so 7 to overwrite pth use "p_ovr' "05_p_exists p_exists "p_ovr null 'should be OK - pth exists and "p_ovr allows overwrites' "01_p_empty p_empty "d_old '3 ' 'should fail - pth is not a dir' "02_p_empty p_empty "d_new '3 6 ' 'should fail - 3 pth is not a dir, 6 cannot overwrite dir' "03_p_empty p_empty "p_old null 'should be OK - pth exists even if empty' "04_p_empty p_empty "p_new '7 ' 'should fail - 7 to overwrite pth use "p_ovr' "01_p_noExist p_noExist "d_old '1 3 ' 'should fail - 1 [dir,path] not found, 3 pth is not a dir' "02_p_noExist p_noExist "d_new '3 ' 'should fail - 3 pth is not a dir' "03_p_noExist p_noExist "p_old '1 ' 'should fail - 1 [dir,path] not found' "04_p_noExist p_noExist "p_new null 'should be OK - containing dir exists, so new file can be added' ; n_cols := 5 ; n_rows := floor ((gage shape inputs) / n_cols) ; testNumL dat1L dat2L stdResultL commentL := cols (n_rows n_cols reshape inputs) ; resultLL := optr EACHRIGHT apply (rows transpose mix dat1L dat2L) ; % ; % here the [dat1L, resultLL] are converted to [short form, codes] for brevity in the output ; % see 'QNial setup - header.ndf' for a somewhat-complete list from all optrs ; pthShortL codedResultL := pthL_resultL_shortenTo_codes dat1L resultLL ; % ; OKL := stdResultL EACHBOTH = codedResultL ; test_tbl := transpose mix (OKL testNumL pthShortL dat2L codedResultL commentL) ; test_tbl := table_add_colTitles test_tbl ('OK' 'test#' '[dir, pth]' 'type' 'calc' 'comments') ; % outputs to p_log, returns for overall testing optr ; % useful for debugging, uncomment : ; % 1 str_overWriteTo_pthOrHandle codedResultL ; p_log EACHRIGHT str_overWriteTo_pthOrHandle '' '+-----+' (link '#] ' (string optr) ' test ' timestamp_DDMMMYYYY_HMS) test_tbl (post link resultLL) 'calc = null means that the test generated nofaults' 'Important point : for d_new, checks dir one level up, for p_new checks current dir' 'All [dir, file]s are in link d_Qtest "fileops/"' 'For [d,p]_new, the next highest subDir in the d_new string is checked for existance' '26Oct2021 Still need tests for faults [8, 9, 10], and add other tests as well to be sure' '' (2 3 reshape 'test sub[dir, pth]' 'n_OK' 'n_total' (string optr) (sum OKL) n_rows ) '' ; optr (sum OKL) n_rows } # EACH (gage shape) testNumL dat1L dat2L stdResultL commentL +-----+ IF flag_debug THEN write 'loading pathL_strL_grepOptions_linesTo_pout_test' ; ENDIF ; #] pathL_strL_grepOptions_linesTo_pout_test IS - search strL in pathL, return lines that hit #] [construct, run] a grepExpr, assumes that ALL pathL are valid files! (check before calling!) #] the number of strs is limited in [find, grep, sed] or the expressions exceed maxLength= ?? IF flag_break THEN BREAK ; ENDIF ; pathL_strL_grepOptions_linesTo_pout_test IS { LOCAL inputs n_cols n_rows OKL optr optrArgs resultL p_stdRslt stdResultL test_tbl testNumL pathLL strLL grepOptionL poutL commentL ; NONLOCAL d_Qtest ; % ; optr := "pathL_strL_grepOptions_linesTo_pout ; d_testy := link d_Qtest 'fileops/[test, std, result] files/' ; p_stdRslt := link d_testy 'pathL_strL_grepOptions_linesTo_pout std results.txt' ; p_result := link d_testy 'pathL_strL_grepOptions_linesTo_pout calc results.txt' ; % ; write '' ; write '+-----+' ; write link '#] ' (string optr) ' test ' timestamp_DDMMMYYYY_HMS ; write '' ; % ; % input order [testNumL, pathLL, strLL, grepOptionL, poutL, commentL] ; inputs := "t01 [[link d_testy 'test- file_ops.ndf']] [[' IS OP ']] [' '] '?comment?' "t02 [[link d_testy 'test- file_ops.ndf']] [[' IS ']] [' -w '] '?comment?' "t03 [[link d_testy 'test- file_ops.ndf']] [[' for ']] [' -c '] '?comment?' "t04 [[link d_testy 'test- file_ops.ndf']] [[' for ']] [' -cw '] '?comment?' ; n_cols := 5 ; n_rows := floor ((gage shape inputs) / n_cols) ; testNumL pathLL strLL grepOptionL commentL := cols (n_rows n_cols reshape inputs) ; % ; % Note the [[p_result]] to prevent mix from generating a chrL ; optrArgs := EACH link (rows transpose mix (pathLL strLL grepOptionL (n_rows reshape [[p_result]]) ) ) ; % write optrArgs ; % write (n_rows reshape [p_result]) ; applyArgs := (n_rows reshape optr) EACHBOTH append optrArgs ; EACH apply applyArgs ; strLhitL := path_read_strL p_result ; % ONLY used to setup stdResultL!!, comment out otherwise ; % strL_write_pout strLhitL p_stdRslt ; stdRsltL := path_read_strL p_stdRslt ; diffRslt := host_result link 'diff "' p_stdRslt '" "' p_result '" --suppress-common-lines ' ; IF (= '' diffRslt) THEN OK := n_rows ; ELSE OK := 0 ; ENDIF ; test_tbl := 1 5 reshape ('test#' 'pathLL' 'strLL' 'grepOptionL' 'comments') ; test_tbl := aryL_join_vertical test_tbl (transpose mix (testNumL pathLL strLL grepOptionL commentL)) ; write test_tbl ; write '' ; write 'IF OK ~= n_rows,then you have to check p_result to see which test # failed' ; write (2 3 reshape 'operator' 'OK' 'total' optr OK n_rows ) ; optr OK n_rows } +-----+ # loaddefs link d_Qtest 'fileops/file_ops- test.ndf' IF flag_debug THEN write 'loading pth_backupDatedTo_zArchive_output' ; ENDIF ; #] pth_backupDatedTo_zArchive_output IS OP i_test pinn - common optr to execute & ouput diff to log file # 19Oct2021 initial using current approach to tests # removes the new version of 'backup corrupted' (if that is the test file), which is not corrupted ; # This is so that diff looks at the original corrupted file in z_Archive and generates an error ; # IF AND(isfault p_latestBackup, 'backup corrupted') then this will try rm the "standard file' ; # but bash will signal the attempt - respond "no" to deny rm ; # original corrupted = '211019 17h17m15s test- file_ops, backup corrupted.ndf' ; # IF flag_break THEN BREAK ; ENDIF ; pth_backupDatedTo_zArchive_output IS OP pth { LOCAL p_latestBackup p_temp result ; NONLOCAL d_temp ; % ; result := null ; p_temp := link d_temp 'pth_backupDatedTo_zArchive temp.txt' ; pth_backupDatedTo_zArchive pth ; p_latestBackup := pth_find_latestZarchive pth ; result := p_latestBackup ; write 'p_latestBackup = ' p_latestBackup ; % ; IF (isstring p_latestBackup) THEN IF ('backup corrupted' subStr_in_str p_latestBackup) THEN host link 'rm "' p_latestBackup '" ' ; p_latestBackup := pth_find_latestZarchive pth ; ENDIF ; % ; host (link 'diff --width=85 "' pth '" "' p_latestBackup '" --suppress-common-lines >"' p_temp '" ') ; IF (NOT pth_isEmpty p_temp) THEN result := link result (fault '?pth_backupDatedTo_zArchive error backup is not the same as original') ; ENDIF ; ENDIF ; % ; result } # olde code | grep ' chr_apo '^>' chr_apo ' | sed ' chr_apo 's/^>\ //' chr_apo ' # subStr_in_str 'hello' 'hello Dolly' # 'backup corrupted' subStr_in_str (link d_Qtest 'fileops/test input files/test- file_ops, backup corrupted.ndf') '" --suppress-common-lines >"' p_temp '" 2>&1 ') ; IF ('backup corrupted' subStr_in_str (link EACH string p_latestBackup)) THEN 211019 17h17m15s test- file_ops, backup corrupted.ndf 211021 00h46m56s test- file_ops, backup corrupted.ndf # loaddefs link d_Qtest 'fileops/file_ops- test.ndf' IF flag_debug THEN write 'loading pth_backupDatedTo_zArchive_test' ; ENDIF ; #] pth_backupDatedTo_zArchive_test IS OP p_log - test pth existance #] Notice! : replacement of results with footnote '(1)' : # 010ct2021 initial based on pthL_replace_wordL_test_output # 19Oct2021 revamped using current approach to tests # 26Oct2021 HALF TRANSITIONED, won't work properly yet!! # backups work, worry about this test sometime in the future. IF flag_break THEN BREAK ; ENDIF ; pth_backupDatedTo_zArchive_test IS OP p_log { LOCAL optr d_testy inputs n_cols n_rows testNumL dat1L stdResultL commentL resultLL pthResultNoDateL faultL pthShortL codedResultL codedFaultStrL OKL test_tbl ; NONLOCAL d_Qtest ; % ; optr := "pth_backupDatedTo_zArchive_output ; d_testy := link d_Qtest 'fileops/test input files/' ; % ; inputs := "01_p_exists (link d_Qtest 'fileops/test input files/test- file_ops.ndf') null 'should be OK - pth exists' "01_p_empty (link d_Qtest 'fileops/test input files/test- empty file.txt') null 'should be OK - even if pth is empty' "01_p_noExist (link d_Qtest 'fileops/test input files/test- file_ops2.ndf') '1 ' 'should fail - 1 [dir,path] not found' "01_p_corrupted (link d_Qtest 'fileops/test input files/test- file_ops, backup corrupted.ndf') '3 ' 'should fail - backup file is corrupted' "01_d_zArchNoExist (link d_Qtest 'fileops/dir empty tests (dont add files)/') '1 3 ' 'should fail - 1 d_zArchive doesn"t exist, 2 dir is not a path' ; n_cols := 4 ; n_rows := floor ((gage shape inputs) / n_cols) ; testNumL dat1L stdResultL commentL := cols (n_rows n_cols reshape inputs) ; resultLL := optr EACHRIGHT apply dat1L ; % ; % pthResultNoDateL - drop date eg '210626 13h24m32s ', for later comparison to pthShortL ; pthResultNoDateL := resultLL ; FOR i WITH (tell n_rows) DO IF (isstring resultLL@i) THEN dir fname := pth_extract_dirFname resultLL@i ; pthResultNoDateL@i := link dir (17 drop fname) ; ENDIF ; ENDFOR ; % ; % here [dat1L, resultLL] are converted to [short form, codes] for brevity in the output ; % see 'QNial setup - header.ndf' for a somewhat-complete list from all optrs ; pthShortL codedResultL := pthL_faultLL_shortenTo_Codes dat1L pthResultNoDateL ; % ; OKL := pthShortL EACHBOTH = codedResultL ; test_tbl := transpose mix (OKL testNumL pthShortL codedResultL commentL) ; test_tbl := table_add_colTitles test_tbl ('OK' 'test#' 'dat1' 'calc - fname or fault code(s)' 'comments') ; % ; % outputs to p_log, returns for overall testing optr ; % p_log str_overWriteTo_pthOrHandle codedFaultStrL ; p_log EACHRIGHT str_overWriteTo_pthOrHandle '' '+-----+' (link '#] ' (string optr) ' test ' timestamp_DDMMMYYYY_HMS) test_tbl (post link resultLL) 'calc = null means that the test generated nofaults' 'Important point : for d_new, checks dir one level up, for p_new checks current dir' 'Most dat1 paths are in d_Qtest "fileops/test input files/"' 'Dated result paths are in the "z_Archive" subdir of the dat1 path' '' (2 3 reshape 'test sub[dir, pth]' 'n_OK' 'n_total' (string optr) (sum OKL) n_rows ) '' ; optr (sum OKL) n_rows } +-----+ IF flag_debug THEN write 'loading str_replaceIn_path_output' ; ENDIF ; #] str_replaceIn_path_output IS OP i_test pinn - common optr to execute & ouput diff to log file # 20Nov2020 initial, adapted from 'Website updates- tests.ndf' str_replaceIn_path_output IS OP i_test strOld strNew pstd pinn { LOCAL flog p_log p_temp ; NONLOCAL d_Qtest ; p_log := link d_Qtest 'file_ops- test log.txt' ; flog := open p_log "a ; flog EACHRIGHT writefile '........' (link '# str_replaceIn_path_test example #' (string i_test)) pinn ; close flog ; % ; % from str_replaceIn_path in 'fileops.ndf' ; p_temp := link d_temp 'str_replaceIn_path temp.txt' ; % Note that for tests, flag_backup is false ; str_replaceIn_path o '' strOld strNew pinn ; host (link 'diff --width=85 "' pstd '" "' p_temp '" --suppress-common-lines | grep ' chr_apo '^>' chr_apo ' | sed ' chr_apo 's/^>\ //' chr_apo ' >>"' p_log '"') ; host link 'echo "" >>"' p_log '"' ; } +-----+ IF flag_debug THEN write 'loading str_replaceIn_path_test' ; ENDIF ; #] str_replaceIn_path_test IS OP - test pinn link fixes, write diff to log file # 20Nov2020 initial, adapted from 'Website updates- tests.ndf' str_replaceIn_path_test IS { LOCAL flog p_log i_test strOld strNew pstd pinn ; NONLOCAL d_Qtest ; p_log := link d_Qtest 'file_ops- test log.txt' ; flog := open p_log "a ; flog EACHRIGHT writefile '' '' '**********************************' (link 'str_replaceIn_path_test, ' timestamp) '' ; close flog ; i_test := 0 ; % ; i_test := i_test + 1 ; strOld strNew := '../../../' '[#=; backtrack ;=#]' ; pstd := link d_Qtest 'test- 1872-2020 SP500 index, ratio of opening price to semi-log detrended price.html str_replaceIn_path.html' ; pinn := link d_Qtest 'test- 1872-2020 SP500 index, ratio of opening price to semi-log detrended price.html' ; str_replaceIn_path_output i_test strOld strNew pstd pinn ; } +-----+ IF flag_debug THEN write 'loading path_replace_wordL_test_output' ; ENDIF ; #] path_replace_wordL_test_output IS OP i_test pstd wordOldNew - #] uses common template to execute & ouput diff to log file, for tests flag_backup is false # 29Sep2021 initial, adapted from str_replaceIn_path_output IF flag_break THEN BREAK ; ENDIF ; path_replace_wordL_test_output IS OP i_test pstd wordOldNew { LOCAL cmd flog pinnL p_log pstdL p_temp ; NONLOCAL d_Qtest d_testFileopsFiles p_log_testFileops p_temp_testFileops ; flog := open p_log_testFileops "a ; flog EACHRIGHT writefile '........' (link '# pathL_replace_wordL_test example #' (string i_test)) ; flog EACHRIGHT writefile (EACH second pstd) ; close flog ; % ; % pathL_replace_wordL pinnL wordOldNew l l ; FOR i WITH (tell (gage shape pstd)) DO cmd := link 'diff --width=85 "' pstdL@i '" "' pinnL@i '" --suppress-common-lines | grep ' chr_apo '^>' chr_apo ' | sed ' chr_apo 's/^>\ //' chr_apo ' >>"' p_temp_testFileops '"' ; write cmd ; % host cmd ; host link 'cat "' p_temp_testFileops '" >>"' p_log_testFileops '"' ; host link 'echo "" >>"' p_log_testFileops '"' ; ENDFOR ; % EACH pZarchive_restore pinnL ; IF (path_isEmpty p_log) THEN 0 ELSE 1 ENDIF } # olde code p_temp := link d_temp 'path_replace_wordL_test_output temp.txt' ; +-----+ # loaddefs link d_Qndfs 'Qndfs optr symbol changes.ndf' IF flag_debug THEN write 'loading pathL_replace_wordL_test' ; ENDIF ; #] pathL_replace_wordL_test IS OP - test pinn link fixes, write diff to log file # 29Sep2021 initial, adapted from str_replaceIn_path_test # uncomment to run all tests (insert line below, remove extra line below next test definition) pathL_replace_wordL_test IS { LOCAL flog p_log i_test n_wrong n_total pstdPinnL wordOldNewL ; NONLOCAL p_temp_testFileops d_testFileopsFiles p_temp_testFileops ; % ; p_log := link d_Qtesty 'file_ops- test log.txt' ; flog := open p_log "a ; flog EACHRIGHT writefile '' '' '**********************************' (link 'pathL_replace_wordL_test, ' timestamp) '' ; close flog ; i_test := 0 ; n_wrong n_total := 0 0 ; % ; i_test := i_test + 1 ; wordOldNewL := ['csvTable_readFrom_path' ''] ; pstdPinnL := [ (link d_testFileopsFiles 'test- file_ops.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- file_ops.ndf') ] ; path_replace_wordL_test_output i_test pstdPinnL wordOldNewL } # d_testFileops := link d_Qtest 'fileops/' ; # d_testFileopsFiles := link d_testFileops [test, std, result] files/' ; # p_temp_testFileops := link d_temp 'testFileops - temp.txt' ; # uncomment to run all tests (insert line below, remove extra line below next test definition) pathL_replace_wordL_test IS { LOCAL flog p_log i_test pstdPinnL wordOldNewL ; NONLOCAL d_testFileopsFiles ; % ; p_log := link d_Qtest 'file_ops- test log.txt' ; flog := open p_log "a ; flog EACHRIGHT writefile '' '' '**********************************' (link 'pathL_replace_wordL_test, ' timestamp) '' ; close flog ; i_test := 0 ; % ; i_test := i_test + 1 ; wordOldNewL := ['csvTable_readFrom_path' ''] ; pstdPinnL := [ (link d_testFileopsFiles 'test- file_ops.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- file_ops.ndf') ] ; path_replace_wordL_test_output i_test pstdPinnL wordOldNewL ; % ; i_test := i_test + 1 ; wordOldNewL := ['hhmmss_to_seconds' ''] ; pstdPinnL := [ (link d_testFileopsFiles 'test- QNial setup.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- QNial setup.ndf') ] ; path_replace_wordL_test_output i_test pstdPinnL wordOldNewL ; % ; i_test := i_test + 1 ; wordOldNewL := ['strL_replace_str' ''] ; pstdPinnL := [ (link d_testFileopsFiles 'test- strings.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- strings.ndf') ] ; path_replace_wordL_test_output i_test pstdPinnL wordOldNewL ; % ; i_test := i_test + 1 ; wordOldNewL := ('strL_replace_str' '') ('hhmmss_to_seconds' '') ('strL_replace_str' '') ; pstdPinnL := ( (link d_testFileopsFiles 'test- strings.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- strings.ndf') ) ( (link d_testFileopsFiles 'test- QNial setup.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- QNial setup.ndf') ) ( (link d_testFileopsFiles 'test- strings.ndf pathL_replace_wordL.txt') (link d_testFileopsFiles 'test- strings.ndf') ) ; path_replace_wordL_test_output i_test pstdPinnL wordOldNewL ; } 08********08 #] +-----+ #] TRANSFORMER tests - both [formal, IS OP with opPhr] +-----+ IF flag_debug THEN write 'loading ary1_transStr_isSameStructAs_ary2_test' ; ENDIF ; #] ary1_transStr_isSameStructAs_ary2_test IS - use different transformers with the same test data #] for comparison of ary structures # 'strings- tests.ndf' ary1_transStr_isSameStructAs_ary2_test IS { LOCAL inputs n_cols n_rows optr test_tbl calcL commentL dat1L dat2L OKL stdResultL testNumL eachResultL twigResultL leafResultL overallResults stdResultL ; % ; optr := "ary1_transStr_isSameStructAs_ary2 ; d_testy := link d_Qtest 'fileops/[test, std, result] files/' ; write '' ; write '+-----+' ; write link '#] ' (string optr) ' test ' timestamp_DDMMMYYYY_HMS ; write '' ; % ; inputs := "t01 null [null] ooo '~= EACH (gage shape) null [null]' "t02 (2 5 reshape [null]) (2 5 reshape "b) lol 'here the nulls of dat1 give different shapes (empty)? Im not sure' "t03 `z `t lll 'obvious' "t04 (`z `t) 'zt' lll 'cant see but dat2=(`z `t), [chr, bool] lists are concatenated' "t05 (`z `t) (1 2) lll 'obvious' "t06 'My name is Sue' 'Bert has a bik' lll 'obvious' "t07 'My name is Sue' 'Bert has a bicycle' ooo 'obvious' "t10 (2 5 reshape 'My name is Sue') (2 5 reshape (tell 10)) lll 'obvious' "t11 (2 5 reshape 'My name is Sue') (2 5 reshape (0 1 2 3 4 5 (6 7) 7 8 9)) loo 'EACH is at top level, subAry@(1 1) fails with [TWIG, LEAF]' "t12 (2 2 reshape (1 `t `z ['all'])) (2 2 reshape (1 `t 5 ['all'])) lll 'shows that arrays of same [struct, #items] work, [dat1,dat2] "all" are both strings' "t13 (2 2 reshape (1 `t `z 'all')) (2 2 reshape (1 `t `z "all)) loo '[dat1,dat2] "all" are [str, phrase]' "t14 (2 2 reshape (1 `t `z ['all'])) (2 2 reshape (1 `t (2 2 reshape `a `b `c `d) ['all'])) loo 'same type of situation as t13' "t21 `z `t lll 'n/a - new examples to come, more complex' "t21 `z `t lll 'n/a - new examples to come, more complex' "t22 `z `t lll 'n/a - new examples to come, more complex' ; n_cols := 5 ; n_rows := floor ((gage shape inputs) / n_cols) ; testNumL dat1L dat2L stdResultL commentL := cols (n_rows n_cols reshape inputs) ; % ; eachResultL := optr EACHRIGHT apply (rows transpose mix (dat1L (n_rows reshape ['EACH']) dat2L)) ; twigResultL := optr EACHRIGHT apply (rows transpose mix (dat1L (n_rows reshape ['TWIG']) dat2L)) ; leafResultL := optr EACHRIGHT apply (rows transpose mix (dat1L (n_rows reshape ['LEAF']) dat2L)) ; OKL := stdResultL EACHBOTH = (rows transpose mix eachResultL twigResultL leafResultL) ; % ; test_tbl := transpose mix (OKL testNumL dat1L dat2L eachResultL twigResultL leafResultL commentL) ; test_tbl := table_add_colTitles test_tbl ('OK' 'test#' 'dat1' 'dat2' 'rEACH' 'rTWIG' 'rLEAF' 'commentL') ; write test_tbl ; write '' ; write 'IF OK ~= n_rows,then you have to check fname to see which test # failed' ; write 'all [inn, std, calc] files are in d_testy = ' d_testy ; write 'operator' 'OK' 'total' ; optr (sum (NOT OKL)) n_rows } # EACH (gage shape) testNumL dat1L dat2L stdResultL commentL # enddoc