;;; Bank OCR Kata ;;; Copyright (c) 2015, Peter Kofler, licensed under BSD License. (include "assert.scm") (include "bank-ocr.scm") (assert-list= = "drop" (drop (list 1 2 3) 2) (list 3)) (assert-list= = "take" (take (list 1 2 3) 2) (list 1 2)) ; how to represent an account number? object or string? (define all-digits (list " _ _ _ _ _ _ _ " " | _| _||_||_ |_ ||_||_|" " ||_ _| | _||_| ||_| _|" " " ) ) ; original API was ; List parse(List rawLines) ; ; guiding test against bank-ocr (assert-list= string=? "guiding test" (list "123456789") (bank-ocr all-digits)) ; ; ; unit tests against parse-digit (define ocr-digit-one (list " " " |" " |" ) ) ; should parse 1 (assert-string= "1" (parse-digit ocr-digit-one)) (define ocr-digit-two (list " _ " " _|" "|_ " ) ) ; should parse 2 (assert-string= "2" (parse-digit ocr-digit-two)) ; ; ; unit tests against parse-digits ; should be empty for empty digits (assert-string= "" (parse-digits (list))) ; stub (define (parse-digit ocr-digit) "1" ) ; should parse digit into number for each digit (assert-string= "111" (parse-digits (list ocr-digit-one ocr-digit-one ocr-digit-one))) ; ; ; unit tests against split-digits (assert-list= (list-equals-for string=?) "should split first digit" (list ocr-digit-one) (split-digits ocr-digit-one)) (define two-ocr-digit-one (list " " " | |" " | |" ) ) (assert-list= (list-equals-for string=?) "should split second digit" (list ocr-digit-one ocr-digit-one) (split-digits two-ocr-digit-one)) ; ; ; unit tests against parse-line ; stub (define (split-digits ocr-line) ocr-digit-one ) ; stub (define (parse-digits ocr-digits) "1" ) ; should split and parse first digit (assert-string= "1" (parse-line ocr-digit-one)) ; ; ; unit tests against bank-ocr (assert-list= string=? "should return empty list on empty input" (list) (bank-ocr (list))) ; stub (define (parse-line ocr-line) "123456789" ) (assert-list= string=? "should call parse-line for single group of lines" (list "123456789") (bank-ocr all-digits)) (assert-list= string=? "should call parse-line for each group of lines" (list "123456789" "123456789") (bank-ocr (append all-digits all-digits)))