Skip to content

Commit

Permalink
Solved AED.Test error on test
Browse files Browse the repository at this point in the history
Solves the following error:
`Unable to find /home/charles-pc/Documents/GitHub/audio-analysis/tests/AED.Test/bin/Debug/netcoreapp3.1/testhost.dll. Please publish your test project and retry.`
By added `Microsoft.NET.Test.Sdk` PackageReference.

Work done for #196
  • Loading branch information
Allcharles authored and atruskie committed Mar 22, 2020
1 parent 894012b commit 0a58db5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<LangVersion>8</LangVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand Down
78 changes: 40 additions & 38 deletions tests/AED.Test/AED.Test.fsproj
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseStandardResourceNames>true</UseStandardResourceNames>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Name>AED.Test</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>portable</DebugType>
<Tailcalls>false</Tailcalls>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<Tailcalls>true</Tailcalls>
</PropertyGroup>
<ItemGroup>
<Compile Include="Common.fs" />
<Compile Include="FsCheckArbs.fs" />
<Compile Include="UtilTest.fs" />
<Compile Include="MatlabTest.fs" />
<Compile Include="AcousticEventDetectionTest.fs" />
<Compile Include="GetAcousticEventsTest.fs" />
<Compile Include="EventPatternRecogTest.fs" />
<Compile Include="SpectralPeakTrackTest.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.7.0" />
<PackageReference Include="FsCheck" Version="3.0.0-alpha4" />
<PackageReference Include="FsCheck.Xunit" Version="3.0.0-alpha4" />
<PackageReference Include="FsUnit.xUnit" Version="3.8.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Acoustics.Shared.FSharp\Acoustics.Shared.FSharp.fsproj" />
<ProjectReference Include="..\..\src\AED\AED.fsproj" />
</ItemGroup>
<PropertyGroup>
<UseStandardResourceNames>true</UseStandardResourceNames>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Name>AED.Test</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>portable</DebugType>
<Tailcalls>false</Tailcalls>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<Tailcalls>true</Tailcalls>
</PropertyGroup>
<ItemGroup>
<Compile Include="Common.fs" />
<Compile Include="FsCheckArbs.fs" />
<Compile Include="UtilTest.fs" />
<Compile Include="MatlabTest.fs" />
<Compile Include="AcousticEventDetectionTest.fs" />
<Compile Include="GetAcousticEventsTest.fs" />
<Compile Include="EventPatternRecogTest.fs" />
<Compile Include="SpectralPeakTrackTest.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="FSharp.Core" Version="4.7.0" />
<PackageReference Include="FsCheck" Version="3.0.0-alpha4" />
<PackageReference Include="FsCheck.Xunit" Version="3.0.0-alpha4" />
<PackageReference Include="FsUnit.xUnit" Version="3.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Acoustics.Shared.FSharp\Acoustics.Shared.FSharp.fsproj" />
<ProjectReference Include="..\..\src\AED\AED.fsproj" />
</ItemGroup>
</Project>
54 changes: 27 additions & 27 deletions tests/AED.Test/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ open Acoustics.AED.GetAcousticEvents
open Acoustics.AED.Util
open Microsoft.FSharp
open Microsoft.FSharp.Math

type TestMetadata = {Dir:string; BWthresh:double; smallThreshIn:int; smallThreshOut:int}
let BAC2_20071015_045040 =
{Dir="BAC2_20071015-045040"; BWthresh=9.0; smallThreshIn=200; smallThreshOut=130}
let GParrots_JB2_20090607_173000_wav_minute_3 =
{Dir="GParrots_JB2_20090607-173000.wav_minute_3"; BWthresh=3.0; smallThreshIn=100; smallThreshOut=35}

let testAll f = Seq.iter f [BAC2_20071015_045040; GParrots_JB2_20090607_173000_wav_minute_3]

/// Sets the current directory to be the fictures folders where test resources are kept
Expand All @@ -33,30 +33,30 @@ do
unzip BAC2_20071015_045040.Dir
unzip GParrots_JB2_20090607_173000_wav_minute_3.Dir

let basePath relativePath =
let basePath relativePath =
let codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase);
let codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
let dirPath = Path.GetDirectoryName(codeBasePath);
Path.Combine(dirPath, relativePath);

let loadTestFile2 d f =
let loadTestFile2 d f =
let p = Path.Combine( (basePath matlabPath), d, f)
csvToMatrix p
csvToMatrix p

let loadTestFile f md = loadTestFile2 md.Dir f
let loadTestFile f md = loadTestFile2 md.Dir f

let loadIntEventsFile f md =
let aem = loadTestFile2 md.Dir f
let aem = loadTestFile2 md.Dir f
// matlab matrix indicies are 1 based, F# is 0 based
let dec x = (int x) - 1
seq {for i in 0..(aem.NumCols-1) -> lengthsToRect (dec aem.[0,i]) (dec aem.[1,i]) ((int) aem.[2,i]) ((int) aem.[3,i])}

let loadFloatEventsFile f md =
let aem = loadTestFile2 md.Dir f
let aem = loadTestFile2 md.Dir f
seq {for i in 0..(aem.NumCols-1) -> cornersToRect aem.[0,i] (aem.[0,i]+aem.[1,i]) aem.[3,i] aem.[2,i]}

// TODO would rather use Either than an exception here
let matrixFloatEquals (a:matrix) (b:matrix) d =
let matrixFloatEquals (a:matrix) (b:matrix) d =
// TODO blow up if not same size (a.GetLength(0) = b.GetLength(0) etc)
for i=0 to (a.NumRows-1) do
for j=0 to (a.NumCols-1) do
Expand All @@ -65,7 +65,7 @@ let matrixFloatEquals (a:matrix) (b:matrix) d =
done
done
true

let defToString x = sprintf "%A" x
let rectToString r = sprintf "%f, %f, %f, %f" (left r) (right r) (bottom r) (top r)
let rectToStringI r = sprintf "%i, %i, %i, %i" (left r) (right r) (bottom r) (top r)
Expand All @@ -74,24 +74,24 @@ let seqEqual eq toS xs' ys' =
let xs, ys = Seq.sort xs', Seq.sort ys'
let l = if Seq.length xs = Seq.length ys then None else sprintf "Lengths differ %i vs %i" (Seq.length xs) (Seq.length ys)|> Some
let bs = Seq.map2 eq xs ys
let c =
if Seq.forall id bs
then
let c =
if Seq.forall id bs
then
[None]
else
let is = Seq.choose (fun i -> if not (Seq.nth i bs) then Some(i) else None) {0..(Seq.length(bs)-1)}
let f (i:int) =
else
let is = Seq.choose (fun i -> if not (Seq.item i bs) then Some(i) else None) {0..(Seq.length(bs)-1)}
let f (i:int) =
let i' = i + 1
sprintf "%i th difference at position %i :\r\n" i i +
sprintf "\t Expected[%i]:\t%s\tFound[%i]:\t%s" i (Seq.item i xs |> toS) i (Seq.item i ys |> toS) +
(if i' < Seq.length ys then sprintf "\tFound[%i]:\t%s" i' (Seq.item i' ys |> toS) else "" )
[(Seq.map f is) |> String.concat "\r\n" |> Some ]
[(Seq.map f is) |> String.concat "\r\n" |> Some ]
catOptions (l::c)

let assertSeqEqual eq toS xs ys =
let m = seqEqual eq toS xs ys
if Seq.isEmpty m then
Assert.True(true)
if Seq.isEmpty m then
Assert.True(true)
else
Assert.True(false, "\r\n\r\n" + (String.concat "\r\n\r\n" m) + "\r\n" )

Expand All @@ -108,14 +108,14 @@ let parseStringAsMatrix (input:string) =


[<Fact>]
let ``matrix parsing test`` () =
let ``matrix parsing test`` () =
let pattern = @"
1010101010101010
1010101010101010
1010101010101010
"
let expected =

let expected =
MatrixTopLevelOperators.matrix [|
[|1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0|];
[|1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0; 1.0; 0.0|];
Expand All @@ -133,7 +133,7 @@ let hitsToCoordinates =
matrixToCoordinates (fun x -> x = 1.0)

[<Fact>]
let ``matrix parsing hit to coordinates test`` () =
let ``matrix parsing hit to coordinates test`` () =
let pattern = @"
1000000010000001
1000000101000001
Expand All @@ -146,15 +146,15 @@ let ``matrix parsing hit to coordinates test`` () =


[<Fact>]
let ``matrix order tests for sanities`` () =
let ``matrix order tests for sanities`` () =
let pattern = @"
1470
2581
3692
"
let mString = pattern |> parseStringAsMatrix
let m = MatrixTopLevelOperators.matrix [ [1.0;4.0;7.0;0.0]; [2.0;5.0;8.0;1.0]; [3.0;6.0;9.0;2.0]]

Assert.Equal<matrix>(mString, m)
Assert.Equal(5.0, m.[1,1])
Assert.Equal(9.0, m.[2,2])
Expand Down

0 comments on commit 0a58db5

Please sign in to comment.