-
-
Notifications
You must be signed in to change notification settings - Fork 62
Implement etl #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Implement etl #27
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3cfe7f1
Start writing the exercise
6e691a8
Implement etl with tests
7bfb6bf
Add etl to config.json
a08bce4
ETL: Address comments
cddf708
Address reviews: add contracts
6026663
ETL: Simplify contract testing
71feb18
Remove commented line
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"hamming", | ||
"anagram", | ||
"rna-transcription", | ||
"etl", | ||
"word-count", | ||
"phone-number", | ||
"nucleotide-count", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#lang racket | ||
|
||
(require "etl.rkt") | ||
|
||
(module+ test | ||
(require rackunit rackunit/text-ui) | ||
|
||
(define mixed-case-input (hash 1 '("a" "E" "I" "o" "U" "L" "N" "r" "s" "T") | ||
2 '("D" "G") | ||
3 '("B" "c" "M" "P") | ||
4 '("f" "h" "V" "W" "y") | ||
5 '("K") | ||
8 '("J" "x") | ||
10 '("q" "z"))) | ||
|
||
(define expected (hash "a" 1 "b" 3 "c" 3 "d" 2 "e" 1 "f" 4 "g" 2 | ||
"h" 4 "i" 1 "j" 8 "k" 5 "l" 1 "m" 3 "n" 1 | ||
"o" 1 "p" 3 "q" 10 "r" 1 "s" 1 "t" 1 | ||
"u" 1 "v" 4 "x" 8 "w" 4 "y" 4 "z" 10)) | ||
|
||
(define negative-keys-input (hash 1 '("L" "N") | ||
-3 '("B" "c" "P"))) | ||
|
||
(define listof-chars-input (hash 1 '(#\N #\r #\q))) | ||
|
||
(define suite | ||
(test-suite | ||
"etl tests" | ||
|
||
(test-true "empty hash" | ||
(zero? (hash-count (etl (make-hash))))) | ||
|
||
(test-case | ||
"mixed case input" | ||
(define actual (etl mixed-case-input)) | ||
(check-equal? (hash-count actual) (hash-count expected)) | ||
(for ([k (hash-keys actual)]) | ||
#;(printf "actual: ~a -> ~a, expected: ~a -> ~a\n" | ||
k (hash-ref actual k) | ||
k (hash-ref expected k)) | ||
(check-equal? (hash-ref actual k) | ||
(hash-ref expected k)))) | ||
|
||
(test-exn | ||
"test bad input: negative keys" | ||
exn:fail:contract? (lambda () (etl negative-keys-input))) | ||
|
||
(test-exn | ||
"test bad input: list of non-string values" | ||
exn:fail:contract? (lambda () (etl listof-chars-input))))) | ||
|
||
(run-tests suite)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#lang racket | ||
|
||
(provide etl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#lang racket | ||
|
||
(provide (contract-out | ||
[etl (-> valid-input valid-output)])) | ||
|
||
(define (lower-case? s) (not (regexp-match? #rx"[A-Z]" s))) | ||
|
||
;; Accept upper- or lower-case-letters strings as values | ||
(define valid-input | ||
(hash/c exact-nonnegative-integer? (listof string?))) | ||
|
||
;; Keys will always be lower-case | ||
(define valid-output | ||
(hash/c lower-case? exact-nonnegative-integer?)) | ||
|
||
(define (etl h) | ||
(for*/hash ([(score letter*) (in-hash h)] | ||
[letter (in-list letter*)]) | ||
;(printf "~a: ~a\n" letter score) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might suggest deleting this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approved! |
||
(values (string-downcase letter) score))) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but you can use
for*/hash
to build the result andin-hash
to walk the old table faster.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those I didn't know: duly noted, thanks.