%!PS % begin included library code % see https://codeberg.org/Firedrake/postscript-libraries/ /deepeq { 2 dict begin /a exch def /b exch def a type b type eq { a type /dicttype eq { a length b length eq { << a { pop true } forall b { pop true } forall >> true exch { pop dup a exch known { dup b exch known { dup a exch get exch b exch get deepeq not { pop false } if } { false } ifelse } { false } ifelse } forall } { false } ifelse } { a type dup /arraytype eq exch /stringtype eq or { a length b length eq { true 0 1 a length 1 sub { dup a exch get exch b exch get deepeq not { pop false exit } if } for } { false } ifelse } { a b eq } ifelse } ifelse } { false } ifelse end } bind def /test { /test.count test.count 1 add def { /test.pass test.pass 1 add def } { ( ) print test.count (....) cvs print (-fail) print } ifelse } bind def /reverse { 1 dict begin dup length /l exch def [ exch aload pop 2 1 l { -1 roll } for ] end } bind def /test.start { print (:) print /test.pass 0 def /test.count 0 def } bind def /test.end { ( ) print test.count 0 gt { (Passed ) print test.pass (...) cvs print (/) print test.count (...) cvs print ( \() print test.pass 100 mul test.count idiv (...) cvs print (%\)) print (\r\n) print } if } bind def % end included library code /leftrightsumdiff { 5 dict begin /a exch def /al a length 1 sub def /left al 1 add array def left 0 0 put /right al 1 add array def right 0 0 put 0 1 al 1 sub { /i exch def left i 1 add left i get a i get add put right i 1 add right i get a al i sub get add put } for /right right reverse def [ 0 1 al { /i exch def left i get right i get sub abs } for ] end } bind def (leftrightsumdiff) test.start [10 4 8 3] leftrightsumdiff [15 1 11 22] deepeq test [1] leftrightsumdiff [0] deepeq test [1 2 3 4 5] leftrightsumdiff [14 11 6 1 10] deepeq test test.end