Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Doorcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
9ca4a709
Commit
9ca4a709
authored
Dec 13, 2020
by
Jacob Priddy
👌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for date split and merging
parent
5304af80
Pipeline
#13196
canceled with stages
in 38 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
0 deletions
+130
-0
src/backend/tests/Unit/Source/Entities/SplittableDateTest.php
...backend/tests/Unit/Source/Entities/SplittableDateTest.php
+130
-0
No files found.
src/backend/tests/Unit/Source/Entities/SplittableDateTest.php
0 → 100644
View file @
9ca4a709
<?php
namespace
Tests\Unit\Source\Entities
;
use
Carbon\Carbon
;
use
PHPUnit\Framework\TestCase
;
use
Source\Entities\SplittableDate
;
class
SplittableDateTest
extends
TestCase
{
/** @test */
public
function
it_tests_engulfed_ranges
():
void
{
$d1
=
new
SplittableDate
(
Carbon
::
now
()
->
subMinute
(),
Carbon
::
now
()
->
addHour
());
$d2
=
new
SplittableDate
(
Carbon
::
now
(),
Carbon
::
now
()
->
addMinute
());
$this
->
assertTrue
(
$d1
->
engulfs
(
$d2
));
$this
->
assertFalse
(
$d2
->
engulfs
(
$d1
));
}
/** @test */
public
function
it_tests_engulfed_ranges_when_equal
():
void
{
$s
=
Carbon
::
now
();
$e
=
$s
->
clone
()
->
addMinute
();
$d1
=
new
SplittableDate
(
$s
,
$e
);
$d2
=
new
SplittableDate
(
$s
,
$e
);
$this
->
assertTrue
(
$d1
->
engulfs
(
$d2
));
$this
->
assertTrue
(
$d2
->
engulfs
(
$d1
));
}
/** @test */
public
function
it_tests_overlap_detection
():
void
{
$d1
=
new
SplittableDate
(
Carbon
::
now
()
->
addDay
(),
Carbon
::
now
()
->
addYear
());
$d2
=
new
SplittableDate
(
Carbon
::
now
(),
Carbon
::
now
()
->
addHour
());
$this
->
assertTrue
(
$d1
->
hasNoOverlapWith
(
$d2
));
$this
->
assertTrue
(
$d2
->
hasNoOverlapWith
(
$d1
));
$d1
=
new
SplittableDate
(
Carbon
::
now
()
->
subDay
(),
Carbon
::
now
()
->
addYear
());
$d2
=
new
SplittableDate
(
Carbon
::
now
(),
Carbon
::
now
()
->
addHour
());
$this
->
assertFalse
(
$d1
->
hasNoOverlapWith
(
$d2
));
$this
->
assertFalse
(
$d2
->
hasNoOverlapWith
(
$d1
));
$d1
=
new
SplittableDate
(
Carbon
::
now
(),
Carbon
::
now
()
->
addMinute
());
$d2
=
new
SplittableDate
(
Carbon
::
now
()
->
subMinute
(),
Carbon
::
now
());
$this
->
assertFalse
(
$d1
->
hasNoOverlapWith
(
$d2
));
$this
->
assertFalse
(
$d2
->
hasNoOverlapWith
(
$d1
));
}
/** @test */
public
function
it_tests_date_set_merging
():
void
{
// |--- d1 ---|
// |---d2-------------|
// |---d3---|
// |-----d4---|
// |---d5---|
// |---d6---|
$d1
=
new
SplittableDate
(
Carbon
::
now
()
->
subDay
(),
Carbon
::
now
()
->
subHours
(
20
));
$d2
=
new
SplittableDate
(
Carbon
::
now
(),
Carbon
::
now
()
->
addHour
());
$sameStart
=
Carbon
::
now
()
->
addMinute
();
$d3
=
new
SplittableDate
(
$sameStart
,
Carbon
::
now
()
->
addMinutes
(
10
));
$d4
=
new
SplittableDate
(
$sameStart
,
Carbon
::
now
()
->
addMinutes
(
20
));
$d5
=
new
SplittableDate
(
Carbon
::
now
()
->
addYear
(),
Carbon
::
now
()
->
addYears
(
3
));
$d6
=
new
SplittableDate
(
Carbon
::
now
()
->
addYears
(
2
),
Carbon
::
now
()
->
addYears
(
10
));
// Test null case
$this
->
assertEquals
([],
SplittableDate
::
mergeSet
([]));
// Test case with just 1 in it
$result
=
SplittableDate
::
mergeSet
([
$d1
]);
$this
->
assertCount
(
1
,
$result
);
$this
->
assertEquals
(
$d1
,
$result
[
0
]);
$result
=
SplittableDate
::
mergeSet
([
$d1
,
$d2
,
$d3
,
$d4
,
$d5
,
$d6
]);
$this
->
assertCount
(
3
,
$result
);
$this
->
assertEquals
(
$d1
,
$result
[
0
]);
$this
->
assertEquals
(
$d2
,
$result
[
1
]);
$this
->
assertEquals
(
$d5
->
getBegin
(),
$result
[
2
]
->
getBegin
());
$this
->
assertEquals
(
$d6
->
getEnd
(),
$result
[
2
]
->
getEnd
());
}
/** @test */
public
function
it_tests_date_block_splitting
():
void
{
$toSplit
=
new
SplittableDate
(
Carbon
::
now
()
->
subHour
(),
Carbon
::
now
()
->
addHour
());
$leftNoOverlap
=
new
SplittableDate
(
Carbon
::
now
()
->
subWeek
(),
Carbon
::
now
()
->
subDay
());
$leftOverlap
=
new
SplittableDate
(
Carbon
::
now
()
->
subHours
(
2
),
Carbon
::
now
()
->
subMinutes
(
50
));
$midBlockLarge
=
new
SplittableDate
(
Carbon
::
now
()
->
subMinutes
(
30
),
Carbon
::
now
()
->
addMinutes
(
2
));
$midBlockSmall
=
new
SplittableDate
(
Carbon
::
now
()
->
subMinute
(),
Carbon
::
now
()
->
addMinute
());
$rightMid
=
new
SplittableDate
(
Carbon
::
now
()
->
addMinutes
(
30
),
Carbon
::
now
()
->
addMinutes
(
40
));
$rightOverlap
=
new
SplittableDate
(
Carbon
::
now
()
->
addMinutes
(
50
),
Carbon
::
now
()
->
addHours
(
2
));
$rightNoOverlap
=
new
SplittableDate
(
Carbon
::
now
()
->
addDay
(),
Carbon
::
now
()
->
addWeek
());
$splits
=
$toSplit
->
split
([
$leftNoOverlap
,
$leftOverlap
,
$midBlockLarge
,
$midBlockSmall
,
$rightMid
,
$rightOverlap
,
$rightNoOverlap
,
]);
$this
->
assertCount
(
3
,
$splits
);
$this
->
assertEquals
(
$leftOverlap
->
getEnd
(),
$splits
[
0
]
->
getBegin
());
$this
->
assertEquals
(
$midBlockLarge
->
getBegin
(),
$splits
[
0
]
->
getEnd
());
$this
->
assertEquals
(
$midBlockLarge
->
getEnd
(),
$splits
[
1
]
->
getBegin
());
$this
->
assertEquals
(
$rightMid
->
getBegin
(),
$splits
[
1
]
->
getEnd
());
$this
->
assertEquals
(
$rightMid
->
getEnd
(),
$splits
[
2
]
->
getBegin
());
$this
->
assertEquals
(
$rightOverlap
->
getBegin
(),
$splits
[
2
]
->
getEnd
());
}
/** @test */
public
function
test_split_with_engulfs
():
void
{
$toSplit
=
new
SplittableDate
(
Carbon
::
now
()
->
subMinute
(),
Carbon
::
now
()
->
addMinute
());
$this
->
assertEquals
([],
$toSplit
->
split
([
$toSplit
]));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment