-
Notifications
You must be signed in to change notification settings - Fork 1
Minoka's eventstream puzzler draft #34
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
Draft
kakizaki55
wants to merge
20
commits into
eventstream-puzzler
Choose a base branch
from
minoka-eventstream-puzzler
base: eventstream-puzzler
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
93ba180
mock data written out
kakizaki55 ee7414e
first test written and failing. have mock data all working in the fun…
kakizaki55 c70ed53
made all test, all failing but everything is connected. small typo er…
kakizaki55 c0ec383
changed mock data to "testing"
kakizaki55 deea342
i got a working find score function.
kakizaki55 dd355b3
Merge pull request #30 from olioapps/ts-tests-and-mocks
kakizaki55 377cdfc
algorithim is working all test are passing. took me while.
kakizaki55 4cae4be
Merge pull request #33 from olioapps/ts-function
kakizaki55 0504318
typo fix in test
kakizaki55 4286150
extrapolated scoreEvent into a different function add tests for all f…
kakizaki55 2da0df6
clean up and spacing
kakizaki55 ce3f8fb
spacing
kakizaki55 c8acbc0
more spacing
kakizaki55 4c7dc00
updateing test for more robust descriptions
kakizaki55 745ae4b
clean up and more description for tests
kakizaki55 b644a85
readablitly spacing
kakizaki55 42fc2c4
test consolidated
kakizaki55 5ff359c
updateing/ upgrading testing suit structure
kakizaki55 b8c66a4
mades chagnes to test suit as requested.
kakizaki55 fc77ffa
minor suit naming change
kakizaki55 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 |
---|---|---|
@@ -1,7 +1,82 @@ | ||
//write tests here | ||
import { | ||
firstMockEventStream, | ||
secondMockEventStream, | ||
thirdMockEventStream, | ||
fourthMockEventStream, | ||
firstMockRegion, | ||
secondMockRegion, | ||
} from './mockEventStream' | ||
import { getHighestScoringRegion, findRegionScore, scoreEvent } from "./index" | ||
|
||
describe('Tests will go here!', () => { | ||
it('should pass', () => { | ||
expect(true).toBeTruthy() | ||
describe('testing all functions for getting the highest scoring region of event stream', () => { | ||
|
||
it('should return the first highest scoring region array when there is a tie', () => { | ||
const firstHighestScoringRegion = getHighestScoringRegion(firstMockEventStream) | ||
const firstExpected = [ | ||
{ timestamp: 123123125, eventType: 'new message' }, | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
] | ||
expect(firstHighestScoringRegion).toEqual(firstExpected) | ||
|
||
const secondHighestScoringRegion = getHighestScoringRegion(thirdMockEventStream) | ||
const secondExpected = [ | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
{ timestamp: 123123125, eventType: 'new message' }, | ||
{ timestamp: 123123125, eventType: 'new message' }, | ||
{ timestamp: 123123123, eventType: 'new message' }, | ||
] | ||
expect(secondHighestScoringRegion).toEqual(secondExpected) | ||
}) | ||
|
||
it('should return the correct array regions if there is less then 5 in event stream', () => { | ||
const highestScoringRegion = getHighestScoringRegion(secondMockEventStream) | ||
const expected = [ | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
] | ||
expect(highestScoringRegion).toEqual(expected) | ||
}) | ||
|
||
it('should return the correct array region', () => { | ||
const highestScoringRegion = getHighestScoringRegion(fourthMockEventStream) | ||
const expected = [ | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123124, eventType: 'screenshot' }, | ||
{ timestamp: 123123125, eventType: 'new message' }, | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
] | ||
expect(highestScoringRegion).toEqual(expected) | ||
}) | ||
|
||
it('should give the correct score for each region', () => { | ||
const firstRegionScore = findRegionScore(firstMockRegion) | ||
expect(firstRegionScore).toEqual(8) | ||
|
||
const secondRegionScore = findRegionScore(secondMockRegion) | ||
expect(secondRegionScore).toEqual(9) | ||
}) | ||
|
||
it('should give the correct score for each region even if there is less then 5', () => { | ||
const thirdRegionScore = findRegionScore( | ||
[ | ||
{ timestamp: 123123125, eventType: 'new message' }, | ||
{ timestamp: 123123125, eventType: 'view' }, | ||
{ timestamp: 123123125, eventType: 'screenshot' }, | ||
]) | ||
expect(thirdRegionScore).toEqual(6) | ||
}) | ||
|
||
it('return the correct score value from each event', () => { | ||
expect(scoreEvent({ timestamp: 123123125, eventType: 'view' })).toEqual(2) | ||
|
||
expect(scoreEvent({ timestamp: 123123125, eventType: 'screenshot' })).toEqual(3) | ||
|
||
expect(scoreEvent({ timestamp: 123123125, eventType: 'new message' })).toEqual(1) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1 +1,40 @@ | ||
//Define class/functions here | ||
//Define class/functions here | ||
export interface Event { | ||
timestamp: number | ||
eventType: 'screenshot' | 'view' | 'new message' | ||
} | ||
|
||
export const scoreEvent = (event: Event): number => { | ||
const { eventType } = event | ||
switch (eventType) { | ||
case "new message": | ||
return 1 | ||
case "view": | ||
return 2 | ||
case "screenshot": | ||
return 3 | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
export const findRegionScore = (eventStream: Array<Event>): number => { | ||
const score = eventStream.reduce((acc, event) => { | ||
return acc + scoreEvent(event) | ||
}, 0) | ||
|
||
return score | ||
} | ||
|
||
export const getHighestScoringRegion = (eventStream: Array<Event>): Array<Event> => { | ||
|
||
const eventStreamScore: number[]= eventStream.reduce((acc, next, index): any => { | ||
const eventRegion = eventStream.slice(index, index + 5) | ||
return [...acc, findRegionScore(eventRegion) ] | ||
}, []) | ||
|
||
const max: number = Math.max(...eventStreamScore) | ||
const index: number = eventStreamScore.indexOf(max) | ||
|
||
return eventStream.slice(index, index + 5) | ||
} |
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,209 @@ | ||
import { Event } from "./index" | ||
export const firstMockEventStream: Array<Event> = [ | ||
{ | ||
timestamp: 123123123, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
] | ||
export const secondMockEventStream: Array<Event> = [ | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
] | ||
export const thirdMockEventStream: Array<Event> = [ | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123123, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
] | ||
export const fourthMockEventStream: Array<Event> = [ | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
] | ||
export const firstMockRegion: Array<Event> = [ | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
] | ||
export const secondMockRegion: Array<Event> = [ | ||
{ | ||
timestamp: 123123125, | ||
eventType: "screenshot", | ||
}, | ||
{ | ||
timestamp: 123123124, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "new message", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
{ | ||
timestamp: 123123125, | ||
eventType: "view", | ||
}, | ||
] |
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.
Uh oh!
There was an error while loading. Please reload this page.