Skip to content

Commit 57f6c01

Browse files
committed
Improve unit coverage and fix #57
1 parent 9dcd636 commit 57f6c01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+823
-79
lines changed

Src/Certainties/Action.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@ public readonly partial struct action{
2323

2424
public static loop operator - (action x) => loop._cont;
2525

26-
public static bool operator true (action s)
26+
// NOTE: required since `false` is implemented; there is not
27+
// a known instance where this function would be called.
28+
public static bool operator true(action s)
2729
=> throw new InvOp("truehood cannot be tested (action)");
2830

31+
// NOTE: used in action && action
2932
public static bool operator false (action s) => false;
3033

34+
public override bool Equals(object x) => x is action;
35+
36+
override public int GetHashCode() => 1;
37+
3138
#if AL_OPTIMIZE // --------------------------------------------
3239

3340
public static action done(ValidString reason = null) => _done;
3441

3542
public static failure operator ! (action s) => failure._fail;
3643
#endif
3744

38-
public static implicit operator bool(action self)
39-
=> true;
45+
public static implicit operator bool(action self) => true;
4046

4147
public static implicit operator status(action self)
4248
=> status._done;

Src/Certainties/Failure.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public readonly partial struct failure{
2727
public static bool operator false (failure s)
2828
=> throw new InvOp("falsehood cannot be tested (failure)");
2929

30+
public override bool Equals(object x) => x is failure;
31+
32+
override public int GetHashCode() => -1;
33+
3034
#if AL_OPTIMIZE // --------------------------------------------
3135

3236
public static failure fail(ValidString reason = null) => _fail;

Src/Certainties/Impending.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public static bool operator true (impending s)
4545
public static bool operator false(impending s)
4646
=> throw new InvOp("Cannot test falsehood (impending)");
4747

48+
public override bool Equals(object x)
49+
=> x is impending && Equals((impending)x);
50+
51+
public bool Equals(in impending x) => true;
52+
53+
override public int GetHashCode() => ω;
54+
4855
override public string ToString()
4956
=> ω == -1 ? "impending.fail" : "impending.cont";
5057

Src/Certainties/Loop.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static bool operator true (loop s)
3434
public static bool operator false (loop s)
3535
=> throw new InvOp("falsehood cannot be tested (loop)");
3636

37+
override public int GetHashCode() => 0;
38+
3739
public static implicit operator impending(loop self)
3840
=> impending._cont;
3941

Src/Certainties/Pending.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public static bool operator true (pending s)
3939

4040
public static bool operator false(pending s) => s.ω != 1;
4141

42+
public override bool Equals(object x)
43+
=> x is pending && Equals((pending)x);
44+
45+
public bool Equals(in pending x) => this.ω == x.ω;
46+
47+
override public int GetHashCode() => ω;
48+
4249
public override string ToString()
4350
=> ω == 0 ? "pending.cont" : "pending.done";
4451

Src/Decorators/Drive.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ public class Drive : AbstractDecorator{
2424
return @in.running ? Eval(crit) : Bypass();
2525
}}
2626

27-
public Gate? this[bool @in, bool crit]{ get{
28-
StatusRef.hold = @in ? status.cont() : status.fail();
29-
return @in ? Eval(crit) : Bypass();
30-
}}
27+
public Gate? this[bool @in, bool crit]
28+
=> this[@in ? status.cont() : status.fail(), crit];
3129

3230
protected Gate Eval(bool crit, ValidString reason=null)
3331
=> new Gate(this, crit, new LogData(this, ".", reason));

Src/Decorators/InOut.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Active.Core{
77
public class InOut : Conditional{
88

99
static int uid; internal static int id => uid = ID(uid);
10-
bool passing;
10+
internal bool passing;
1111
int frame;
1212

1313
public Gate? this[bool @in, bool @out]{ get{

Src/Decorators/Once.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public StatusRef this[status s]{ get{
6565
#if !AL_BEST_PERF
6666
partial class Task{
6767
public Self.Gate? Once([Tag] int key = -1)
68-
=> store.Decorator<Self>(key, Self.id)?.pass;
68+
=> store.Decorator<Self>(key, Self.id).pass;
6969
}
7070
#endif
7171

Src/Decorators/Timeout.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class Timeout : Conditional, Conditional.OptionalArguments{
99

1010
static int uid; internal static int id => uid = ID(uid);
1111
public float duration = 1;
12-
float stamp;
12+
internal float stamp;
1313
int frame;
1414

15-
bool enabled => stamp != -1;
15+
internal bool enabled => stamp != -1;
1616

1717
public Timeout() => stamp = time;
1818

@@ -36,7 +36,7 @@ public Gate? this[float s]{ get{
3636

3737
override public void OnStatus(status s) => OnStatus(s.running);
3838

39-
void OnStatus(bool running)
39+
internal void OnStatus(bool running)
4040
=> stamp = enabled ^ running ? (enabled ? -1 : time) : stamp;
4141

4242
override public action Reset(){ stamp = -1; return @void(); }

Src/Decorators/Undef.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ public class Undef : AbstractDecorator{
1414

1515
static int uid; internal static int id => uid = ID(uid);
1616
protected Random _random;
17-
float stamp;
17+
internal float stamp;
1818
status value;
1919

2020
public Undef(){}
2121

22-
protected Random random => _random ?? (_random = new Random());
22+
internal Random random => _random ?? (_random = new Random());
2323

2424
public status this[float s]{ get{
25-
var t = time; if(stamp == 0) stamp = t; var remaining = s + stamp - t;
25+
var t = time;
26+
if(stamp == 0) stamp = t;
27+
var remaining = s + stamp - t;
2628
return (
2729
(remaining > 0) ? value
2830
: (value = status.@unchecked(random.Next(-1, 2)))

0 commit comments

Comments
 (0)