Skip to content

Commit

Permalink
Merge pull request #110 from marcin-golebiowski/master
Browse files Browse the repository at this point in the history
Refactor of decorators and factories + bug fixes
  • Loading branch information
marcin-golebiowski authored Jul 28, 2019
2 parents b0e9a8d + 72148bb commit 9619ae7
Show file tree
Hide file tree
Showing 58 changed files with 1,657 additions and 1,284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SpiceSharp" Version="2.7.3" />
<PackageReference Include="SpiceSharp" Version="2.7.6" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="SpiceSharp" Version="2.7.3" />
<PackageReference Include="SpiceSharp" Version="2.7.6" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
16 changes: 16 additions & 0 deletions src/SpiceSharpParser.IntegrationTests/Stochastic/DevLotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ public void DevLotMultipleComponentsSameModel()
Assert.NotEqual(exports[3], exports[5]);
Assert.NotEqual(exports[4], exports[5]);
}

[Fact]
public void When_Mc_Expect_NoException()
{
var result = ParseNetlist(
"Monte Carlo Analysis - DevLot - Diodes",
"D1 OUT 0 1N914",
"V1 OUT 0 0",
".model 1N914 D(Is=2.52e-9 LOT 10% Rs=0.568 DEV 20%)",
".OP",
".LET is {@1N914#D1[Is]}",
".MC 1000 OP is MAX",
".END");

RunSimulationsAndReturnExports(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="SpiceSharp" Version="2.7.3" />
<PackageReference Include="SpiceSharp" Version="2.7.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Linq;
using SpiceSharpParser.Common.Evaluation;
using SpiceSharpParser.ModelReaders.Netlist.Spice;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Configurations;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Updates;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations.Configurations;
using Xunit;

namespace SpiceSharpParser.Tests.ModelReaders.Spice.Readers.Controls.Simulations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Linq;
using SpiceSharpParser.Common.Evaluation;
using SpiceSharpParser.ModelReaders.Netlist.Spice;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Configurations;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Updates;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.Controls.Simulations.Configurations;
using Xunit;

namespace SpiceSharpParser.Tests.ModelReaders.Spice.Readers.Controls.Simulations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void GenerateSimpleResistor()
var resistor = generator.Generate("r1", "R1", "r", parameters, context);

Assert.NotNull(resistor);
context.Received().SetParameter(resistor, "resistance", "1.2", false);
context.Received().SetParameter(resistor, "resistance", "1.2", true, onload: false);
}

[Fact]
Expand Down
36 changes: 36 additions & 0 deletions src/SpiceSharpParser.Tests/Parsers/SpiceExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
using SpiceSharpParser.ModelReaders.Netlist.Spice.Evaluation;
using SpiceSharpParser.Parsers.Expression;
using System;
using System.Collections.Generic;
using Xunit;

namespace SpiceSharpParser.Tests.Parsers
{
public class SpiceExpressionTests
{
public class CustomFunction : IFunction<string, double>
{
public CustomFunction()
{
ArgumentsCount = 2;
}

public double Logic(string image, string[] args, IEvaluator evaluator, ExpressionContext context)
{
return 0;
}

public int ArgumentsCount { get; set; }
public bool Infix { get; set; }
public string Name { get; set; }
public Type ArgumentType => typeof(string);
public Type OutputType { get; }
}

[Fact]
public void When_ExpressionHasUnknownParameter_Expect_Exception()
{
Expand All @@ -18,6 +38,21 @@ public void When_ExpressionHasUnknownParameter_Expect_Exception()
Assert.Throws<UnknownParameterException>(() => parser.Parse("x + 1", new ExpressionParserContext()).Value(new ExpressionEvaluationContext() { ExpressionContext = new ExpressionContext() }));
}

[Fact]
public void When_ExpressionHasStringFunctionWithParameters_Expect_Exception()
{
// arrange
var parser = new SpiceExpressionParser();

var context = new ExpressionEvaluationContext() {ExpressionContext = new ExpressionContext()};
context.ExpressionContext.AddFunction("v", new CustomFunction());
var parserContext = new ExpressionParserContext();
parserContext.Functions.Add("v", new List<IFunction>() { new CustomFunction()});

// act and assert
parser.Parse("1 + v(2,0) + 3", parserContext).Value(context);
}

[Fact]
public void When_ExpressionHasKnownParameter_Expect_Reference()
{
Expand Down Expand Up @@ -45,6 +80,7 @@ public void When_ExpressionHasSinFunction_Expect_Reference()
Assert.Equal(1, parser.Parse("sin(0) + 1", new ExpressionParserContext(context.Functions)).Value(new ExpressionEvaluationContext() { ExpressionContext = context }));
}


[Fact]
public void When_ExpressionHasParameters_Expect_Reference()
{
Expand Down
4 changes: 2 additions & 2 deletions src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NSubstitute" Version="4.2.0" />
<PackageReference Include="SpiceSharp" Version="2.7.3" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="SpiceSharp" Version="2.7.6" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Loading

0 comments on commit 9619ae7

Please sign in to comment.