#!/bin/sh global test_description := ''basic tests for the SHA1 array implementation'' source ./test-lib.sh proc echo20 { global prefix := $(1:+$1 ) shift while test $# -gt 0 { echo "$prefix$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1" shift } } test_expect_success 'ordered enumeration' ' echo20 "" 44 55 88 aa >expect && { echo20 append 88 44 aa 55 && echo for_each_unique } | test-sha1-array >actual && test_cmp expect actual ' test_expect_success 'ordered enumeration with duplicate suppression' ' echo20 "" 44 55 88 aa >expect && { echo20 append 88 44 aa 55 && echo20 append 88 44 aa 55 && echo for_each_unique } | test-sha1-array >actual && test_cmp expect actual ' test_expect_success 'lookup' ' { echo20 append 88 44 aa 55 && echo20 lookup 55 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -eq 1 ' test_expect_success 'lookup non-existing entry' ' { echo20 append 88 44 aa 55 && echo20 lookup 33 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -lt 0 ' test_expect_success 'lookup with duplicates' ' { echo20 append 88 44 aa 55 && echo20 append 88 44 aa 55 && echo20 lookup 55 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -ge 2 && test "$n" -le 3 ' test_expect_success 'lookup non-existing entry with duplicates' ' { echo20 append 88 44 aa 55 && echo20 append 88 44 aa 55 && echo20 lookup 66 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -lt 0 ' test_expect_success 'lookup with almost duplicate values' ' { echo "append 5555555555555555555555555555555555555555" && echo "append 555555555555555555555555555555555555555f" && echo20 lookup 55 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -eq 0 ' test_expect_success 'lookup with single duplicate value' ' { echo20 append 55 55 && echo20 lookup 55 } | test-sha1-array >actual && n=$(cat actual) && test "$n" -ge 0 && test "$n" -le 1 ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"basic tests for the SHA1 array implementation">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: echo20 body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:prefix) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonPlus arg_word: {($ VSub_Number "$1") (" ")} ) spids: [24 29] ) ) } spids: [22] ) ] spids: [22] ) (C {(shift)}) (While cond: [(C {(test)} {($ VSub_Pound "$#")} {(-gt)} {(0)})] body: (DoGroup children: [ (C {(echo)} { (DQ ($ VSub_Name "$prefix") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ($ VSub_Number "$1") ) } ) (C {(shift)}) ] spids: [47 80] ) ) ] spids: [19] ) spids: [14 18] ) (C {(test_expect_success)} {(SQ <"ordered enumeration">)} { (SQ <"\n"> <"\techo20 \"\" 44 55 88 aa >expect &&\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo for_each_unique\n"> <"\t} | test-sha1-array >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"ordered enumeration with duplicate suppression">)} { (SQ <"\n"> <"\techo20 \"\" 44 55 88 aa >expect &&\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo for_each_unique\n"> <"\t} | test-sha1-array >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 lookup 55\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -eq 1\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup non-existing entry">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 lookup 33\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -lt 0\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup with duplicates">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 lookup 55\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -ge 2 &&\n"> <"\ttest \"$n\" -le 3\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup non-existing entry with duplicates">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 append 88 44 aa 55 &&\n"> <"\t\techo20 lookup 66\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -lt 0\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup with almost duplicate values">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo \"append 5555555555555555555555555555555555555555\" &&\n"> <"\t\techo \"append 555555555555555555555555555555555555555f\" &&\n"> <"\t\techo20 lookup 55\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -eq 0\n"> ) } ) (C {(test_expect_success)} {(SQ <"lookup with single duplicate value">)} { (SQ <"\n"> <"\t{\n"> <"\t\techo20 append 55 55 &&\n"> <"\t\techo20 lookup 55\n"> <"\t} | test-sha1-array >actual &&\n"> <"\tn=$(cat actual) &&\n"> <"\ttest \"$n\" -ge 0 &&\n"> <"\ttest \"$n\" -le 1\n"> ) } ) (C {(test_done)}) ] )