Revoked builder approach
This commit is contained in:
parent
93632f45fb
commit
bb517a1074
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise.Contracts;
|
||||
|
||||
namespace CubicNoise.Builders
|
||||
{
|
||||
public sealed class NoiseBuilder
|
||||
{
|
||||
public NoiseTypes NoiseType { get; set; } = NoiseTypes.UNKNOWN;
|
||||
|
||||
public int NoiseSeed { get; set; } = new Random().Next();
|
||||
|
||||
public Dictionary<IParameterName, int> NoiseIntParameters = new Dictionary<IParameterName, int>();
|
||||
|
||||
private NoiseBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
public static NoiseBuilder New()
|
||||
{
|
||||
return new NoiseBuilder();
|
||||
}
|
||||
|
||||
public NoiseBuilder Type(NoiseTypes type)
|
||||
{
|
||||
this.NoiseType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoiseBuilder Seed(int seed)
|
||||
{
|
||||
this.NoiseSeed = seed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoiseBuilder Seed(string seed)
|
||||
{
|
||||
this.NoiseSeed = seed.GetHashCode();
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoiseBuilder SetParam(IParameterName param, int value)
|
||||
{
|
||||
this.NoiseIntParameters[param] = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise.Noisers;
|
||||
|
||||
namespace CubicNoise.Builders
|
||||
{
|
||||
public sealed class Parameters
|
||||
{
|
||||
private Parameters()
|
||||
{
|
||||
}
|
||||
|
||||
public static CubicNoiseParameterKinds Cubic(CubicNoiseParameterKinds kind)
|
||||
{
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,10 @@
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>C:\Users\Thorsten\Downloads\repos\CubicNoise\CubicNoise\CubicNoise.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
|
8
CubicNoise/CubicNoise.xml
Normal file
8
CubicNoise/CubicNoise.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>CubicNoise</name>
|
||||
</assembly>
|
||||
<members>
|
||||
</members>
|
||||
</doc>
|
16
CubicNoise/EngineParameters.cs
Normal file
16
CubicNoise/EngineParameters.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise.Contracts;
|
||||
|
||||
namespace CubicNoise
|
||||
{
|
||||
public sealed class EngineParameters
|
||||
{
|
||||
public int Seed { get; set; } = new Random().Next();
|
||||
|
||||
public NoiseTypes Type { get; set; } = NoiseTypes.UNKNOWN;
|
||||
|
||||
public Dictionary<IParameterName, int> IntParameters { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise.Builders;
|
||||
using CubicNoise.Contracts;
|
||||
using CubicNoise.Noisers;
|
||||
|
||||
@ -23,7 +22,7 @@ namespace CubicNoise
|
||||
};
|
||||
}
|
||||
|
||||
public static NoiseEngine CreateEngine(NoiseBuilder builder) => new NoiseEngine(builder.NoiseType, builder.NoiseSeed, builder.NoiseIntParameters);
|
||||
public static NoiseEngine Create(EngineParameters parameters) => new NoiseEngine(parameters.Type, parameters.Seed, parameters?.IntParameters);
|
||||
|
||||
public float Get(float x) => this.engine.Get(x);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise.Builders;
|
||||
using CubicNoise.Contracts;
|
||||
|
||||
namespace CubicNoise.Noisers
|
||||
|
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Text;
|
||||
using CubicNoise.Builders;
|
||||
using CubicNoise.Contracts;
|
||||
|
||||
namespace CubicNoise.Noisers
|
||||
{
|
||||
public sealed class CubicNoiseParameterKinds
|
||||
{
|
||||
private CubicNoiseParameterKinds()
|
||||
{
|
||||
}
|
||||
|
||||
public static CubicNoiseParameterKinds Int { get; } = new CubicNoiseParameterKinds();
|
||||
|
||||
public IParameterName Use(CubicNoiseIntParameters name) => name;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CubicNoise;
|
||||
using CubicNoise.Builders;
|
||||
using CubicNoise.Contracts;
|
||||
using CubicNoise.Noisers;
|
||||
using NUnit.Framework;
|
||||
|
||||
@ -11,9 +11,92 @@ namespace CubicNoiseTests
|
||||
public class NoiseBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void SimpleBuild()
|
||||
public void StraightCreation()
|
||||
{
|
||||
var engine = NoiseEngine.CreateEngine(NoiseBuilder.New().Type(NoiseTypes.CUBIC_NOISE).Seed("test seed").SetParam(Parameters.Cubic(CubicNoiseParameterKinds.Int.Use(CubicNoiseIntParameters.OCTAVE))))
|
||||
var engine = NoiseEngine.Create(new EngineParameters
|
||||
{
|
||||
Seed = "test seed".GetHashCode(),
|
||||
Type = NoiseTypes.CUBIC_NOISE,
|
||||
IntParameters = new Dictionary<IParameterName, int>
|
||||
{
|
||||
{ CubicNoiseIntParameters.OCTAVE, 57 },
|
||||
{ CubicNoiseIntParameters.PERIOD_X, 12 },
|
||||
{ CubicNoiseIntParameters.PERIOD_Y, 16 },
|
||||
},
|
||||
});
|
||||
|
||||
Assert.That(engine, Is.Not.Null);
|
||||
|
||||
try
|
||||
{
|
||||
engine.Get(16f);
|
||||
engine.Get(16f, 18f);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("Noise engine seems not to be implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoParameters()
|
||||
{
|
||||
var engine = NoiseEngine.Create(new EngineParameters());
|
||||
|
||||
Assert.That(engine, Is.Not.Null);
|
||||
|
||||
try
|
||||
{
|
||||
engine.Get(16f);
|
||||
engine.Get(16f, 18f);
|
||||
Assert.That(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("Noise engine seems not to be implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullCheck()
|
||||
{
|
||||
try
|
||||
{
|
||||
var engine = NoiseEngine.Create(null);
|
||||
Assert.Fail("Null instead of parameters should not work.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.That(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartialParameters()
|
||||
{
|
||||
var engine = NoiseEngine.Create(new EngineParameters
|
||||
{
|
||||
Seed = "test seed".GetHashCode(),
|
||||
Type = NoiseTypes.CUBIC_NOISE,
|
||||
IntParameters = new Dictionary<IParameterName, int>
|
||||
{
|
||||
{ CubicNoiseIntParameters.OCTAVE, 57 },
|
||||
{ CubicNoiseIntParameters.PERIOD_X, 12 },
|
||||
//{ CubicNoiseIntParameters.PERIOD_Y, 16 }, // is missing!
|
||||
},
|
||||
});
|
||||
|
||||
Assert.That(engine, Is.Not.Null);
|
||||
|
||||
try
|
||||
{
|
||||
engine.Get(16f);
|
||||
engine.Get(16f, 18f);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("Noise engine seems not to be implemented.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user