Skip to content

Commit 776242e

Browse files
authored
Merge pull request #1 from dmannock/emptyintervals-update-from-rampart-1.1.0.0
Ported issue fix #2 - Handle empty intervals at the bounds
2 parents 768a28e + 2165b0f commit 776242e

File tree

7 files changed

+124
-26
lines changed

7 files changed

+124
-26
lines changed

Diff for: .vscode/tasks.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"command": "dotnet",
9+
"type": "shell",
10+
"args": [
11+
"build",
12+
"src",
13+
"/property:GenerateFullPaths=true",
14+
"/consoleloggerparameters:NoSummary"
15+
],
16+
"group": {
17+
"kind": "build",
18+
"isDefault": true
19+
},
20+
"presentation": {
21+
"reveal": "silent"
22+
},
23+
"problemMatcher": "$msCompile"
24+
},
25+
{
26+
"label": "test",
27+
"command": "dotnet",
28+
"args": [
29+
"run",
30+
"-p",
31+
"test/FsharpRampart.PropTests.fsproj"
32+
],
33+
"group": {
34+
"kind": "test",
35+
"isDefault": true
36+
}
37+
}
38+
]
39+
40+
}

Diff for: CHANGELOG.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# FsharpRampart Change Log
3+
All notable changes to this project will be documented in this file aiming to be true to the ported source.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## 2.0.0 - 2020-05-02
9+
10+
Latest code ported. Behavior of relates has changed to accommodate the handling of empty intervals at the bounds. I consider this a breaking change, hence the major version bump.
11+
12+
### Changed
13+
- Add predicates for detecting empty intervals - Ported
14+
- Removed show function - unneeded with built-in fsharp print functions
15+
16+
### Fixed
17+
- Handle empty intervals at the bounds - Ported issue fix [#2](https://github.com/tfausak/rampart/issues/2)
18+
19+
## [1.0.2] - 2020-03-16
20+
21+
### Changed
22+
- Version bumped to more closely match ported repo
23+
24+
### Fixed
25+
- Ported issue fix [PR #5](https://github.com/tfausak/rampart/pull/5)
26+
27+
## [0.1.0] - 2020-03-14
28+
29+
### Added
30+
- Initial port of the haskell rampart lib to fsharp

Diff for: README.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
# FsharpRampart
22
.NET port (written in F#) of the [Haskell Rampart library](https://github.com/tfausak/rampart) by [Taylor Fausak](https://taylor.fausak.me/2020/03/13/relate-intervals-with-rampart/).
33

4+
Available on [Nuget](https://www.nuget.org/packages/FsharpRampart/)
5+
46
![][interval relations]
57

68
## Examples
79

8-
```csharp
10+
```fsharp
911
open FsharpRampart
1012
relate (toInterval (2, 4)) (toInterval (3, 5))
1113
// Output: Overlaps
1214
```
1315

14-
```csharp
16+
```fsharp
1517
let dt1 = (DateTime(2020,01,01), DateTime(2020,03,14)) |> toInterval
1618
let dt2 = (DateTime(2019,01,01), DateTime(2020,03,14)) |> toInterval
1719
relate dt1 dt2
1820
//Output: Finishes
1921
```
2022

21-
```csharp
23+
```fsharp
2224
invert Before
2325
//Output: After
2426
```
2527

28+
```fsharp
29+
toInterval (2, 4) |> lesser
30+
// Output: 2
31+
32+
toInterval (2, 4) |> greater
33+
// Output: 4
34+
```
35+
36+
```fsharp
37+
toInterval (2, 2) |> isEmpty
38+
// Output: true
39+
40+
toInterval (2, 3) |> isEmpty
41+
// Output: false
42+
43+
toInterval (2, 3) |> isNonEmpty
44+
// Output: true
45+
```
46+
2647
## C# interop
2748
Usage is similar but to make it easier to consume using directives will be needed depending on which module the function is in.
2849
```csharp
@@ -41,4 +62,7 @@ invert(Relation.Before);
4162
//Output: After
4263
```
4364

65+
## Changelog
66+
[View changelog](/CHANGELOG.md)
67+
4468
[interval relations]: ./interval-relations.svg

Diff for: src/FsharpRampart.fsproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>FsharpRampart</PackageId>
5-
<Version>1.0.2</Version>
5+
<Version>2.0.0</Version>
66
<Authors>Dan Mannock</Authors>
77
<Company>Dan Mannock</Company>
88
<PackageTags>F#;FSharp;Functional Programming</PackageTags>

Diff for: src/Library.fs

+20-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ module Interval =
2727

2828
let greater (Interval(_, y)) = y
2929

30+
let isEmpty (Interval(x, y)) = x = y
31+
32+
let isNonEmpty (Interval(x, y)) = x <> y
33+
3034
type private ComparisonResult = | LT | EQ | GT
3135
let private compare x y =
3236
if x < y then LT
@@ -39,19 +43,21 @@ module Interval =
3943
let gxly = compare (greater x) (lesser y)
4044
let gxgy = compare (greater x) (greater y)
4145
match (lxly, lxgy, gxly, gxgy) with
42-
| (EQ, _, _, EQ) -> Equal
43-
| (_, _, LT, _) -> Before
44-
| (_, _, EQ, _) -> Meets
45-
| (_, EQ, _, _) -> MetBy
46-
| (_, GT, _, _) -> After
47-
| (LT, _, _, LT) -> Overlaps
48-
| (LT, _, _, EQ) -> FinishedBy
49-
| (LT, _, _, GT) -> Contains
50-
| (EQ, _, _, LT) -> Starts
51-
| (EQ, _, _, GT) -> StartedBy
52-
| (GT, _, _, LT) -> During
53-
| (GT, _, _, EQ) -> Finishes
54-
| (GT, _, _, GT) -> OverlappedBy
46+
| (EQ, _, _, EQ) -> Equal
47+
| ( _, _, LT, _) -> Before
48+
| (LT, _, EQ, LT) -> Meets
49+
| ( _, _, EQ, _) -> Overlaps
50+
| (GT, EQ, _, GT) -> MetBy
51+
| ( _, EQ, _, _) -> OverlappedBy
52+
| ( _, GT, _, _) -> After
53+
| (LT, _, _, LT) -> Overlaps
54+
| (LT, _, _, EQ) -> FinishedBy
55+
| (LT, _, _, GT) -> Contains
56+
| (EQ, _, _, LT) -> Starts
57+
| (EQ, _, _, GT) -> StartedBy
58+
| (GT, _, _, LT) -> During
59+
| (GT, _, _, EQ) -> Finishes
60+
| (GT, _, _, GT) -> OverlappedBy
5561

5662
let invert = function
5763
| After -> Before
@@ -66,4 +72,4 @@ module Interval =
6672
| OverlappedBy -> Overlaps
6773
| Overlaps -> OverlappedBy
6874
| StartedBy -> Starts
69-
| Starts -> StartedBy
75+
| Starts -> StartedBy

Diff for: test/PropTests.fs

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ let fromIntervalSameAsReadingLesserAndGreater (x: int) (y: int) =
1717

1818
Check.Quick fromIntervalSameAsReadingLesserAndGreater
1919

20+
let relationWithSameValuesIsEqual (x: int) =
21+
toInterval(x, x) |> isEmpty
22+
23+
Check.Quick relationWithSameValuesIsEqual
24+
2025
let relationWithIntervalsOrderSwappedAndInverted<'T when 'T : comparison> (x: 'T, y: 'T) (a: 'T, b: 'T) =
2126
let interval1 = toInterval(x, y)
2227
let interval2 = toInterval(a, b)

Diff for: test/repltests.fsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#r "bin/Debug/netstandard2.0/FsharpRampart.dll"
1+
#r "../src/bin/Debug/netstandard2.0/FsharpRampart.dll"
22
open System
33
open FsharpRampart
44

@@ -15,17 +15,10 @@ let test() =
1515
relate (toInterval (2, 4)) (toInterval (3, 5))
1616
// Relation = Overlaps
1717

18-
(1, 2)
19-
|> toInterval
20-
|> show
21-
2218
let dt1 = (DateTime(2020,01,01), DateTime(2020,03,14)) |> toInterval
2319
let dt2 = (DateTime(2019,01,01), DateTime(2020,03,14)) |> toInterval
2420
relate dt1 dt2
2521
// Relation = Finishes
26-
27-
Before
28-
|> Relation.show
2922

3023
invert Before
3124
// Relation = After

0 commit comments

Comments
 (0)