-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ReadingData with Day type (#6)
* Update main component and reducers to include the 'day' type * Removed unused types
- Loading branch information
Showing
5 changed files
with
64 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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,30 @@ | ||
open Types; | ||
open PageType; | ||
|
||
module Day { | ||
let now = () => { | ||
let dateString = () => | ||
Js.Date.setHoursMSMs(Js.Date.make(), ~hours=0., ~minutes=0., ~seconds=0., ~milliseconds=0.,()) | ||
|> Js.Date.fromFloat | ||
|> Js.Date.toISOString; | ||
|
||
{ date: dateString(), entries: []}; | ||
}; | ||
|
||
let empty = { date: "", entries: []}; | ||
|
||
let createEntry = (nextId, pt, pageCount) => { | ||
id: nextId, | ||
kind: pt, | ||
value: pageCount | ||
}; | ||
|
||
let appendEntry: (day, entry) => day = | ||
(rd, entry) => { | ||
{ date: rd.date, entries: [entry, ...rd.entries] }; | ||
}; | ||
|
||
let pageCount = (rd: day) => rd.entries | ||
|> List.map(i => float_of_int(i.value) *. PageType.pageScore(i.kind)) | ||
|> List.fold_left((a, b) => a +. b, 0.); | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,32 +1,48 @@ | ||
open Jest; | ||
|
||
open ReadingData; | ||
open Day; | ||
open Types; | ||
|
||
describe("ReadingData", () => { | ||
describe("Day", () => { | ||
open Expect; | ||
|
||
describe("ReadingData.empty", () => { | ||
test("Is an empty ReadingData object", () => | ||
expect(List.length(ReadingData.empty.entries)) |> toBe(0)); | ||
describe("Day.empty", () => { | ||
test("Is an empty Day object", () => | ||
expect(List.length(Day.empty.entries)) |> toBe(0)); | ||
}); | ||
|
||
describe("ReadingData.createEntry", () => { | ||
describe("Day.now", () => { | ||
test("Creates a Date with no reading entires", () => | ||
expect(List.length(Day.now().entries)) |> toBe(0)); | ||
|
||
test("Sets the date field", () => | ||
expect(String.length(Day.now().date)) |> toBeGreaterThan(0)); | ||
|
||
test("Sets the date field with a parsable date", () => { | ||
let testDate = Day.now().date; | ||
|
||
let otherDate = Js.Date.parse(testDate) |> Js.Date.toISOString; | ||
|
||
expect(testDate) |> toEqual(otherDate) | ||
}); | ||
}); | ||
|
||
describe("Day.createEntry", () => { | ||
test("Can create an entry type", () => | ||
expect(ReadingData.createEntry(1, Lyric, 1)) |> toEqual({id: 1, kind: Lyric, value: 1})); | ||
expect(Day.createEntry(1, Lyric, 1)) |> toEqual({id: 1, kind: Lyric, value: 1})); | ||
}); | ||
|
||
describe("ReadingData.pageCount", () => { | ||
describe("Day.pageCount", () => { | ||
test("Counts all pages types to give a weighted total", () => | ||
expect(ReadingData.pageCount({ entries: [ | ||
expect(Day.pageCount({ date: "", entries: [ | ||
{id: 1, kind: Book, value: 1}, | ||
{id: 2, kind: Lyric, value: 1}, | ||
{id: 3, kind: Manga, value: 1}, | ||
{id: 4, kind: Net, value: 1}, | ||
{id: 5, kind: News, value: 1},]})) |> toBeLessThan(5.)); | ||
|
||
test("Returns 0 for an empty list of entries", () => | ||
expect(ReadingData.pageCount(ReadingData.empty)) |> toBe(0.)); | ||
expect(Day.pageCount(Day.empty)) |> toBe(0.)); | ||
}); | ||
|
||
}); |