Skip to content

Commit

Permalink
Update workoutSegment.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapvanEkris authored Dec 15, 2024
1 parent da3865a commit ba83098
Showing 1 changed file with 107 additions and 3 deletions.
110 changes: 107 additions & 3 deletions app/engine/utils/workoutSegment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test('Test workoutSegment behaviour with setting a distance interval', () => {
}

const testSegment = createWorkoutSegment()
testSegment.setStart(startingPoint)
testSegment.setEnd(distanceInterval)
testDistanceFromStart(testSegment, startingPoint, 0)
testTimeSinceStart(testSegment, startingPoint, 0)
Expand All @@ -104,9 +105,9 @@ test('Test workoutSegment behaviour with setting a time interval', () => {
targetDistance: 0,
targetTime: 485,
split: {
type: 'distance',
targetDistance: 500,
targetTime: 0
type: 'time',
targetDistance: 0,
targetTime: 60
}
}

Expand All @@ -126,6 +127,7 @@ test('Test workoutSegment behaviour with setting a time interval', () => {
}

const testSegment = createWorkoutSegment()
testSegment.setStart(startingPoint)
testSegment.setEnd(distanceInterval)
testDistanceFromStart(testSegment, startingPoint, 0)
testTimeSinceStart(testSegment, startingPoint, 0)
Expand All @@ -145,6 +147,108 @@ test('Test workoutSegment behaviour with setting a time interval', () => {
testExtrapolation(testSegment, middlePoint, endPoint, 485, 2025)
})

test('Test split behaviour when setting a distance interval', () => {
const distanceInterval = {
type: 'distance',
targetDistance: 2025,
targetTime: 0,
split: {
type: 'distance',
targetDistance: 500,
targetTime: 0
}
}

const startingPoint = {
totalMovingTime: 0,
totalLinearDistance: 0
}

const middlePoint = {
totalMovingTime: 118,
totalLinearDistance: 490
}

const endPoint = {
totalMovingTime: 122,
totalLinearDistance: 510
}

const testSegment = createWorkoutSegment()
const testSplit = createWorkoutSegment()
testSegment.setStart(startingPoint)
testSegment.setEnd(distanceInterval)
testSplit.setStart(startingPoint)
testSplit.setEnd(testSegment.getSplit())
testDistanceFromStart(testSplit, startingPoint, 0)
testTimeSinceStart(testSplit, startingPoint, 0)
testdistanceToEnd(testSplit, startingPoint, 500)
testTimeToEnd(testSplit, startingPoint, undefined)
testIsEndReached(testSplit, startingPoint, false)
testDistanceFromStart(testSplit, middlePoint, 490)
testTimeSinceStart(testSplit, middlePoint, 118)
testdistanceToEnd(testSplit, middlePoint, 10)
testTimeToEnd(testSplit, middlePoint, undefined)
testIsEndReached(testSplit, middlePoint, false)
testDistanceFromStart(testSplit, endPoint, 510)
testTimeSinceStart(testSplit, endPoint, 122)
testdistanceToEnd(testSplit, endPoint, -10)
testTimeToEnd(testSplit, endPoint, undefined)
testIsEndReached(testSplit, endPoint, true)
testExtrapolation(testSplit, middlePoint, endPoint, 120, 500)
})

test('Test split behaviour with setting a time interval', () => {
const distanceInterval = {
type: 'time',
targetDistance: 0,
targetTime: 485,
split: {
type: 'time',
targetDistance: 0,
targetTime: 60
}
}

const startingPoint = {
totalMovingTime: 0,
totalLinearDistance: 0
}

const middlePoint = {
totalMovingTime: 480,
totalLinearDistance: 2000
}

const endPoint = {
totalMovingTime: 490,
totalLinearDistance: 2050
}

const testSegment = createWorkoutSegment()
const testSplit = createWorkoutSegment()
testSegment.setStart(startingPoint)
testSegment.setEnd(distanceInterval)
testSplit.setStart(startingPoint)
testSplit.setEnd(testSegment.getSplit())
testDistanceFromStart(testSplit, startingPoint, 0)
testTimeSinceStart(testSplit, startingPoint, 0)
testdistanceToEnd(testSplit, startingPoint, 500)
testTimeToEnd(testSplit, startingPoint, undefined)
testIsEndReached(testSplit, startingPoint, false)
testDistanceFromStart(testSplit, middlePoint, 490)
testTimeSinceStart(testSplit, middlePoint, 118)
testdistanceToEnd(testSplit, middlePoint, 10)
testTimeToEnd(testSplit, middlePoint, undefined)
testIsEndReached(testSplit, middlePoint, false)
testDistanceFromStart(testSplit, endPoint, 510)
testTimeSinceStart(testSplit, endPoint, 122)
testdistanceToEnd(testSplit, endPoint, -10)
testTimeToEnd(testSplit, endPoint, undefined)
testIsEndReached(testSplit, endPoint, true)
testExtrapolation(testSplit, middlePoint, endPoint, 120, 500)
})

function testDistanceFromStart (testedSegment, testedDatapoint, expectedValue) {
assert.ok(testedSegment.distanceFromStart(testedDatapoint) === expectedValue, `Expected distance from the start should be ${expectedValue}, encountered ${testedSegment.distanceFromStart(testedDatapoint)}`)
}
Expand Down

0 comments on commit ba83098

Please sign in to comment.