Difference between revisions of "Spreadsheet To Dictionaries Assignment"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | Follows [[Spreadsheet_Assignment|Spreadsheet]] | + | Follows [[Spreadsheet_Assignment|Spreadsheet]] and [[Chained_Dictionaries_Assignment|Chained Dictionaries] exercises. |
− | + | =Code To Implement= | |
+ | ==structure SpreadsheetToDictionaries== | ||
===to_dictionaries_using_headers_as_keys=== | ===to_dictionaries_using_headers_as_keys=== | ||
fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list = | fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list = | ||
Line 44: | Line 45: | ||
NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising [https://smlfamily.github.io/Basis/list.html#SIG:LIST.Empty:EXN Empty] seems like a reasonable thing to do. | NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising [https://smlfamily.github.io/Basis/list.html#SIG:LIST.Empty:EXN Empty] seems like a reasonable thing to do. | ||
+ | |||
+ | =Testing= | ||
+ | {{SMLUnitTesting|run_spreadsheet_to_dictionaries_testing|spreadsheet_to_dictionaries}} |
Revision as of 03:31, 19 October 2022
Follows Spreadsheet and [[Chained_Dictionaries_Assignment|Chained Dictionaries] exercises.
Contents
Code To Implement
structure SpreadsheetToDictionaries
to_dictionaries_using_headers_as_keys
fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list = raise NotYetImplemented
Given this spreadsheet:
Name | Uniform Number | Birth Year | Games Played | Goals | Assists |
Bobby Orr | 4 | 1948 | 657 | 270 | 645 |
Wayne Gretzky | 99 | 1961 | 1487 | 894 | 1963 |
Mario Lemieux | 66 | 1965 | 915 | 690 | 1033 |
to_dictionaries_using_headers_as_keys
should return a list with 3 single list dictionaries, one for each non-header row. The dictionaries would be filled with entries for each column, using the cell in the header of the column as the key and the cell in the particular row of the column as the value.
[ { TEXT("Name") => TEXT("Bobby Orr"), TEXT("Uniform Number") => INTEGER(4), TEXT("Birth Year") => INTEGER(1948), TEXT("Games Played") => INTEGER(657), TEXT("Goals") => INTEGER(270), TEXT("Assists") => INTEGER(645) }, { TEXT("Name") => TEXT("Wayne Gretzky"), TEXT("Uniform Number") => INTEGER(99), TEXT("Birth Year") => INTEGER(1961), INTEGER("Games Played") => INTEGER(1487), TEXT("Goals") => INTEGER(894), TEXT("Assists") => INTEGER(1963) }, { TEXT("Name") => TEXT("Mario Lemieux"), TEXT("Uniform Number") => INTEGER(66), TEXT("Birth Year") => INTEGER(1965), INTEGER("Games Played") => INTEGER(915), TEXT("Goals") => INTEGER(690), TEXT("Assists") => INTEGER(1033) } ]
NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising Empty seems like a reasonable thing to do.
Testing
source folder: | src/test/sml/spreadsheet_to_dictionaries |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_spreadsheet_to_dictionaries_testing.sml |
how to run with CM.make verbosity on: | sml run_spreadsheet_to_dictionaries_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.