Skip to content

Commit 366d3ab

Browse files
committed
Improve cover (optimized mode) closes #60
1 parent 57f6c01 commit 366d3ab

File tree

10 files changed

+122
-24
lines changed

10 files changed

+122
-24
lines changed

Src/Details/Stateful/AbstractDecoratorDetails.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public LogData(AbstractDecorator s, object tg, string r){
3535
}
3636

3737
public string Reason()
38+
#if AL_OPTIMIZE
39+
=> null;
40+
#else
3841
=> TraceFormat.DecoratorReason(target, reason);
42+
#endif
3943

4044
}
4145

Src/Details/StatusDetails.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ internal status(in status s, LogTrace trace){
4949

5050
status(in status s, int value){ this = s; ω = value; }
5151

52-
status(in status s, in status prev){
52+
internal status(in status s, in status prev){
5353
this = s;
5454
meta = log ? new Meta(meta, prev: new Ref(prev))
5555
: new Meta(meta);
5656
}
5757

58-
status(in status s, in status prev, int value){
58+
internal status(in status s, in status prev, int value){
5959
this = s; ω = value;
6060
meta = log ? new Meta(meta, prev: new Ref(prev))
6161
: new Meta(meta);
@@ -96,7 +96,9 @@ public override bool Equals(object x)
9696

9797
public override int GetHashCode() => ω;
9898

99-
public override string ToString() => StatusFormat.ToString(this);
99+
public override string ToString()
100+
=> (ω >= -1 || ω <= +1) ? StatusFormat.ToString(this)
101+
: $"invalid_status({ω})";
100102

101103
internal static status @unchecked(int value)
102104
=> new status(value, @unchecked: true);

Src/Details/StatusDetailsOptimized.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ internal status(int value, LogTrace trace=null, status[] children = null)
1515

1616
internal status(StatusValue value, LogTrace trace=null) => ω = (int)value;
1717

18-
status(int value) => ω = value;
19-
status(in status s, LogTrace trace) => this = s;
20-
status(in status s, int value) => ω = value;
21-
status(in status s, in status prev) => this = s;
22-
status(in status s, in status prev, int value) => ω = value;
18+
internal status(int value) => ω = value;
19+
20+
internal status(in status s, LogTrace trace) => this = s;
21+
22+
internal status(in status s, int value) => ω = value;
23+
24+
internal status(in status s, in status prev) => this = s;
25+
26+
internal status(in status s, in status prev, int value)
27+
=> ω = value;
2328

2429
public static status operator & (status x, status y) => y;
2530
public static status operator | (status x, status y) => y;
@@ -55,9 +60,10 @@ public override string ToString(){
5560
}
5661
}
5762

58-
internal status ViaScope(object scope, string reason=null) => this;
63+
//internal status ViaScope(object scope, string reason=null) => this;
5964

60-
static LogTrace LogTrace(object scope, string reason=null) => null;
65+
//internal static LogTrace LogTrace(object scope,
66+
// string reason=null) => null;
6167

6268
}}
6369

Src/Details/StatusFormat.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class StatusFormat{
1818

1919
public static string Decorator(object x) => $"<{x.GetType().Name[0]}>";
2020

21-
public static string LastPathComponent(string path) => path.Substring(
22-
path.LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1
23-
).Replace(".cs", null);
24-
2521
#if !AL_OPTIMIZE
2622

23+
public static string LastPathComponent(string path) => path.Substring(
24+
path.LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1
25+
).Replace(".cs", null);
26+
2727
public static string CallTree(in status status){
2828
var builder = new StringBuilder();
2929
Hierarchy(status, builder, tabs: Tabs);

Src/Details/TraceFormat.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if !(UNITY_EDITOR || DEBUG)
2+
#define AL_OPTIMIZE
3+
#endif
4+
15
using System;
26
using ArgEx = System.ArgumentException;
37

@@ -25,6 +29,7 @@ public static string LogTrace(LogTrace trace){
2529
return trace.next == null ? @out : $"{@out} -> {LogTrace(trace.next)}";
2630
}
2731

32+
#if !AL_OPTIMIZE
2833
public static string DecoratorReason(object target, string reason)
2934
=> ( (string)target == "."
3035
? $"{ReasonField(reason)}"
@@ -33,6 +38,7 @@ public static string DecoratorReason(object target, string reason)
3338
public static string Scope(LogTrace t) => t?.scope.ToString();
3439

3540
static string DecoratorTarget(object target) => target?.ToString() ?? "?";
41+
#endif
3642

3743
/* Used by TraceFormat.LogTrace */
3844
static string Reason(string reason, bool isDecorator)

Src/Gig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public abstract partial class Gig {
1313
protected static readonly LogString log = null;
1414

1515
public virtual status Step()
16+
#if AL_OPTIMIZE
17+
=> status._fail;
18+
#else
1619
=> status.fail(log && "`Step` is not implemented");
20+
#endif
1721

1822
public action Do(params object[] x) => @void();
1923

Tests/Decorators/TestAbstractDecorator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
#if !(UNITY_EDITOR || DEBUG)
2+
#define AL_OPTIMIZE
3+
#endif
4+
15
using NUnit.Framework;
26
using Active.Core;
37
using Active.Core.Details;
48

59
public class TestAbstractDecorator
610
: DecoratorTest<TestAbstractDecorator.Concrete>{
711

12+
#if AL_OPTIMIZE
13+
[Test] public void Reason_isNull() => o(
14+
new AbstractDecorator.LogData(null, null, null)
15+
.Reason(), null );
16+
#endif
17+
818
[Test] public void Nature(){
919
o( x is Resettable );
1020
o( x is IDecorator );

Tests/StringsTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using NUnit.Framework;
2+
using Active.Core;
3+
4+
public class TestStrings : TestBase{
5+
6+
[Test] public void StatusValues(){
7+
o( Strings.status.names,
8+
new string[]{"failing", "running", "done"});
9+
}
10+
11+
}

Tests/TestLogTrace.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ [Test] public void Constructors_nologging(){
1515

1616
// TODO - don't think LogTrace allows a null scope; then
1717
// the `?.` in `Matches` will never be used.
18-
[Test] public void Matches(){
18+
[Test] public void Matches_1(){
1919
var trace = new LogTrace(new object(), null);
2020
trace.Matches(null, null);
2121
}
2222

23+
[Test] public void Matches_2(){
24+
var obj = "foo";
25+
var trace = new LogTrace("foo", null);
26+
trace.Matches(obj, null);
27+
}
28+
2329
}

Tests/TestStatus.cs

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,36 @@ public class TestStatus : CoreTest {
2020
[Test] public void Fail_Func() => o ( fail().failing );
2121
[Test] public void Running_Func() => o ( cont().running );
2222

23-
#if !AL_OPTIMIZE
23+
// --------------------------------------------------------------
2424

25-
LogString log = null;
25+
#if AL_OPTIMIZE
26+
// optimized mode
27+
[Test] public void Construct_withLogTrace(){
28+
status a = done();
29+
o( new status(a, trace: null).complete );
30+
}
31+
32+
// optimized mode
33+
[Test] public void ToString_(){
34+
o ( fail.ToString() , "fail" );
35+
o ( cont.ToString() , "cont" );
36+
o ( done.ToString(), "done" );
37+
o ( status.@unchecked(5).ToString(), "invalid_status(5)");
38+
}
39+
40+
// optimized mode
41+
[Test] public void Indexer(){
42+
o( done[null].complete );
43+
}
44+
45+
// optimized mode
46+
[Test] public void WithValidString(){
47+
o( (done % (ValidString)null).complete );
48+
}
49+
50+
#endif
2651

27-
[Test] public void Construct_value_and_trace(
52+
[Test] public void Construct_withValueAndTrace(
2853
[Values(true, false)] bool lg){
2954
var _log = status.log;
3055
//
@@ -33,6 +58,30 @@ [Test] public void Construct_value_and_trace(
3358
status.log = _log;
3459
}
3560

61+
[Test] public void Construct_withStatusAndPrev_1(){
62+
status a = done(), b = fail();
63+
o( new status(a, prev: b).complete );
64+
}
65+
66+
[Test] public void Construct_withStatusAndPrev_2()
67+
=> o( new status(done(), prev: fail(), value: 5).complete);
68+
69+
[Test] public void Equals_type_mismatch(){
70+
o(done.Equals( "1" ), false);
71+
}
72+
73+
// Optimized mode
74+
[Test] public void ViaDecorator()
75+
=> o( done.ViaDecorator(null, null).complete );
76+
77+
// optimized mode
78+
//[Test] public void LogTrace()
79+
//=> o( status.LogTrace(null, null), null );
80+
81+
#if !AL_OPTIMIZE
82+
83+
LogString log = null;
84+
3685
[Test] public void Construct_logtraceMissing(){
3786
Assert.Throws<ArgEx>( () =>
3887
{ var z = new status(0, null, null); });
@@ -63,10 +112,6 @@ [Test] public void ConstructWithCIAndReason(){
63112
}
64113
}
65114

66-
[Test] public void Equals_type_mismatch(){
67-
o(done.Equals( "1" ), false);
68-
}
69-
70115
[Test] public void Validate(){
71116
Assert.Throws<ArgEx>( () => status.Validate(12) );
72117
}
@@ -107,6 +152,7 @@ [Test] public void ToString_(){
107152
o ( fail.ToString() , "failing ()" );
108153
o ( cont.ToString() , "running ()" );
109154
o ( done.ToString(), "done ()" );
155+
//o ( new status(5).ToString(), "invalid_status(5)");
110156
}
111157

112158
[Test] public void Condoner_withTrace(){
@@ -143,11 +189,12 @@ [Test] public void Eval(){
143189

144190
[Test] public void StatusConsts(){
145191
o( (status)status.@void(), done);
192+
o( (status)status.@false(), fail);
146193
o( (status)status.flop(), fail);
147194
o( (status)status.forever(), cont);
148195
}
149196

150-
#pragma warning restore 612
197+
#pragma warning restore 618
151198

152199
// ==============================================================
153200

@@ -282,7 +329,9 @@ [Test] public void Truehood(){
282329
}
283330

284331
// Don't know how to test this
285-
[Test] public void Falsehood(){}
332+
[Test] public void Falsehood(){
333+
o( done && @fail, @fail );
334+
}
286335

287336
[Test] public void RunningIsTrueAndFalse(){
288337
if(cont) Assert.Pass(); else Assert.Fail();

0 commit comments

Comments
 (0)