Skip to content

Commit

Permalink
Last recorder test, transcription errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Jul 16, 2024
1 parent 784ca41 commit 1e9a86d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 44 deletions.
4 changes: 2 additions & 2 deletions AltCover.Recorder.Tests/Recorder.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ module AltCoverTests =
Assert.True(Adapter.addSample ("module", 23, Time 0L), "Test 7")

Assert.True(
Adapter.addSample ("module", 24, new Both(Pair.Create(1, 0))),
Adapter.addSample ("module", 24, new Both(Pair.Create(0, 1))),
"Test 8"
)

Assert.True(
Adapter.addSample ("module", 25, new Both(Pair.Create(1, 0))),
Adapter.addSample ("module", 25, new Both(Pair.Create(0, 1))),
"Test 9"
)

Expand Down
128 changes: 86 additions & 42 deletions AltCover.Recorder/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ internal class SimpleVisit : Sampled
public SimpleVisit(int visit) : base(visit)
{
}

public override bool Equals(object obj)
{
if (obj is SimpleVisit visit1)
{
return visit == visit1.visit;
}
return false;
}

public override int GetHashCode()
{
return visit.GetHashCode();
}
}

internal class CallVisit : Sampled
Expand All @@ -153,6 +167,20 @@ public CallVisit(int visit, int call) : base(visit)
{
this.call = call;
}

public override bool Equals(object obj)
{
if (obj is CallVisit visit1)
{
return (visit == visit1.visit) && (call == visit1.call);
}
return false;
}

public override int GetHashCode()
{
return visit.GetHashCode() ^ call.GetHashCode();
}
}

internal class TimeVisit : Sampled
Expand All @@ -163,13 +191,28 @@ public TimeVisit(int visit, long time) : base(visit)
{
this.time = time;
}

public override bool Equals(object obj)
{
if (obj is TimeVisit visit1)
{
return (visit == visit1.visit) && (time == visit1.time);
}
return false;
}

public override int GetHashCode()
{
return visit.GetHashCode() ^ time.GetHashCode();
}
}

#if DEBUG

internal static class I
#else
private static class I

private static class I
#endif
{
internal static readonly ResourceManager resources =
Expand Down Expand Up @@ -304,9 +347,7 @@ internal static string signalFile

internal static Tracer trace
{
#if DEBUG
set { __trace = value; }
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
get { return __trace; }
}
Expand Down Expand Up @@ -344,9 +385,7 @@ internal static void initialiseTrace(Tracer t)

internal static bool recording
{
#if DEBUG
set { __recording = value; }
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
get { return __recording; }
}
Expand Down Expand Up @@ -508,43 +547,48 @@ internal static bool takeSample(Sampling strategy, string moduleId, int hitPoint
{
if (strategy == Sampling.All)
return true;
throw new NotImplementedException("takeSample");

// let internal takeSample strategy moduleId hitPointId(context: Track) =
// match strategy with
// | Sampling.All -> true
// | _ ->
// (match context with
// | Null -> [Visit hitPointId]
// | Time t ->
// [Visit hitPointId
// TimeVisit(hitPointId, t)]
// | Call c ->
// [Visit hitPointId
// CallVisit(hitPointId, c)]
// | Both b ->
// [Visit hitPointId
// TimeVisit(hitPointId, b.Time)
// CallVisit(hitPointId, b.Call)]
// | _ -> context |> InvalidDataException.Throw)
// |> Seq.map(fun hit ->
// if samples.ContainsKey(moduleId) then
// let next = samples.[moduleId]

// let mutable hasPointKey =
// next.ContainsKey(hit)

// if hasPointKey |> not then
// lock next(fun () ->
// hasPointKey<- next.ContainsKey(hit)

// if hasPointKey |> not then
// next.Add(hit, true))

// not hasPointKey
// else
// false)
// |> Seq.fold(||) false // true if any are novel -- all must be evaluated

Sampled[] sampleds = null;
if (context is Null)
sampleds = new Sampled[] { new SimpleVisit(hitPointId) };
else if (context is Time)
sampleds = new Sampled[] { new SimpleVisit(hitPointId),
new TimeVisit(hitPointId, ((Time)context).Value) };
else if (context is Call)
sampleds = new Sampled[] { new SimpleVisit(hitPointId),
new CallVisit(hitPointId, ((Call)context).Value) };
else if (context is Both)
{
var b = (Both)context;
sampleds = new Sampled[] { new SimpleVisit(hitPointId),
new TimeVisit(hitPointId, b.Value.Time),
new CallVisit(hitPointId, b.Value.Call)};
}
else throw new InvalidDataException(context.ToString());

var wanted = false;
foreach (var sample in sampleds)
{
if (!samples.ContainsKey(moduleId))
continue;
var next = samples[moduleId];
var hasPointKey = next.ContainsKey(sample);
if (!hasPointKey)
{
lock (next)
{
hasPointKey = next.ContainsKey(sample);
if (!hasPointKey)
{
next.Add(sample, true);
}
}

wanted = wanted || !hasPointKey;
}
}

return wanted;
}

/// <summary>
Expand Down

0 comments on commit 1e9a86d

Please sign in to comment.