本文整理汇总了C#中Chain类的典型用法代码示例。如果您正苦于以下问题:C# Chain类的具体用法?C# Chain怎么用?C# Chain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Chain类属于命名空间,在下文中一共展示了Chain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExecutionError
public void TestExecutionError()
{
Chain<int, int> chain = new Chain<int, int>()
.Link<int>(x => x)
.Link<int>(x =>
{
if (x == 0)
throw new NullReferenceException(x.ToString());
else
return x;
})
.Link<int>(x => 100);
ChainExecutionException chEE = null;
try
{
int outcome = chain.Execute(0);
}
catch (ChainExecutionException chee)
{
chEE = chee;
}
Assert.IsNotNull(chEE);
Assert.AreEqual<string>("0", chEE.InnerException.Message);
}
示例2: IsLegalResponse
public IsLegalResponse(ReasonEnum reason = ReasonEnum.Fine)
{
this.Reason = reason;
this.Killed = new List<Chain>();
this.MergeResultant = new Chain();
this.AbsorbedInMerge = new List<Chain>();
}
示例3: Base64SerializationTest
public void Base64SerializationTest()
{
var generator = new PrimitveGenerator (PrimitiveType.Sphere, 12);
var generator2 = new PrimitveGenerator (PrimitiveType.Cube, 234702);
var chain = new Chain<List<GameObject>> ()
.Link (generator)
.Link (generator2)
;
var serialized = new Base64DeSerializer<Chain<List<GameObject>>> (chain);
Assert.IsNotEmpty (serialized.Serialized);
Assert.AreEqual (chain, serialized.Data);
var byteSize = serialized.Serialized.Length * sizeof (Char);
Console.WriteLine ("Serialized data is " + byteSize + " bytes.");
var deserialized = new Base64DeSerializer<Chain<List<GameObject>>> (serialized.Serialized);
Assert.AreEqual (serialized.Serialized, deserialized.Serialized);
Assert.AreEqual (serialized.Data.Elements.Count, deserialized.Data.Elements.Count);
var deserializedGenerator = (PrimitveGenerator)deserialized.Data.Elements[0];
Assert.AreEqual (generator.Amount, deserializedGenerator.Amount);
Assert.AreEqual (generator.Type, deserializedGenerator.Type);
var deserializedGenerator2 = (PrimitveGenerator)deserialized.Data.Elements[1];
Assert.AreEqual (generator2.Amount, deserializedGenerator2.Amount);
Assert.AreEqual (generator2.Type, deserializedGenerator2.Type);
}
示例4: RunFullBlockTest
public void RunFullBlockTest()
{
var generator = new FullBlockTestGenerator(Network.Main);
ValidationState validation = new ValidationState(Network.Main);
validation.CheckMerkleRoot = false;
validation.CheckProofOfWork = false;
var scan =
new ScanState(new PubKeyHashScanner(generator.CoinbaseKey.PubKey.ID),
new Chain(),
new Account(),
0);
scan.CheckDoubleSpend = true;
var mainChain = new Chain(Network.Main);
var indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), CreateBlockStore());
indexed.Put(Network.Main.GetGenesis());
foreach(var test in generator.GetBlocksToTest(true, true).list.OfType<BlockAndValidity>())
{
indexed.Put(test.block);
mainChain.GetOrAdd(test.block.Header);
Assert.True(scan.Process(mainChain, indexed) == test.connects);
//if(!)
//{
// Assert.True(test.throwsException);
//}
Assert.Equal(test.heightAfterBlock, scan.Chain.Height);
Assert.Equal(test.hashChainTipAfterBlock, scan.Chain.Tip.HashBlock);
mainChain.SetTip(scan.Chain.Tip);
}
}
示例5: Calculate
/// <summary>
/// Calculation method.
/// </summary>
/// <param name="chain">
/// Source sequence.
/// </param>
/// <param name="link">
/// Link of intervals in chain.
/// </param>
/// <returns>
/// Average remoteness dispersion <see cref="double"/> value.
/// </returns>
public double Calculate(Chain chain, Link link)
{
List<int> intervals = new List<int>();
for (int i = 0; i < chain.Alphabet.Cardinality; i++)
{
intervals.AddRange(chain.CongenericChain(i).GetIntervals(link).ToList());
}
List<int> uniqueIntervals = intervals.Distinct().ToList();
List<int> intervalsCounts = new List<int>();
for (int i = 0; i < uniqueIntervals.Count; i++)
{
var currentInterval = uniqueIntervals[i];
intervalsCounts.Add(intervals.Count(interval => interval == currentInterval));
}
double result = 0;
double gDelta = geometricMean.Calculate(chain, link);
int n = (int)intervalsCount.Calculate(chain, link);
for (int i = 0; i < uniqueIntervals.Count; i++)
{
int nk = intervalsCounts[i];
double kDelta = uniqueIntervals[i];
double centeredRemoteness = Math.Log(kDelta, 2) - Math.Log(gDelta, 2);
result += nk == 0 ? 0 : centeredRemoteness * centeredRemoteness * nk / n;
}
return result;
}
示例6: Run
public static void Run()
{
Chain<int, double> chain = new Chain<int, double>()
.Link<int>(x =>
{
// Generate random array of ints
int[] nums = new int[x];
Random rand = new Random();
for (int i = 0; i < x; i++)
{
nums[i] = rand.Next(100);
}
return nums;
})
.Link<int[]>(x =>
{
// order the numbers (pointless but why not)
return x.OrderBy(y => y).ToArray();
})
.Link<int[]>(x =>
{
// compute the average and return it
double average = 0.0;
for (int i = 0; i < x.Length; i++)
{
average += x[i];
}
return average / x.Length;
});
// Execute our chain, passing in 100 as the initial argument
double avg = chain.Execute(100);
Console.WriteLine("Average int chain finished, result: " + avg);
}
示例7: Calculate
/// <summary>
/// Calculation method.
/// </summary>
/// <param name="chain">
/// Source sequence.
/// </param>
/// <param name="link">
/// Link of intervals in chain.
/// </param>
/// <returns>
/// Average remoteness <see cref="double"/> value.
/// </returns>
public double Calculate(Chain chain, Link link)
{
double depth = depthCalculator.Calculate(chain, link);
int nj = (int)intervalsCount.Calculate(chain, link);
return nj == 0 ? 0 : depth / nj;
}
示例8: ChainSummary
internal ChainSummary(Chain chain, int playerId)
{
this.ChainId = chain.Id;
var playerGuess = chain.Guesses.FirstOrDefault(g => g.Contributor.UserId == playerId);
this.PlayerGuess = new PlayerGuess(playerGuess.Content, playerGuess.Type.ToString());
this.OtherContributors =
chain.Guesses.Where(g => g.Contributor.UserId != playerId).Select(g => g.Contributor.UserName).ToArray();
}
示例9: EndChainInvolvement
public void EndChainInvolvement(Chain chain)
{
if (Chain != null && Chain == chain)
{
Chain.DecrementInvolvement();
Chain = null;
}
}
示例10: Calculate
/// <summary>
/// Calculation method.
/// </summary>
/// <param name="chain">
/// Source sequence.
/// </param>
/// <param name="link">
/// Link of intervals in chain.
/// </param>
/// <returns>
/// AT skew value as <see cref="double"/>.
/// </returns>
public double Calculate(Chain chain, Link link)
{
DnaProcessor.CheckDnaAlphabet(chain.Alphabet);
var a = remotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A")), link);
var t = remotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T")), link);
return (int)(a + t) == 0 ? 0 : (a - t) / (a + t);
}
示例11: MultiDeepMarkovChain
/// <summary>
/// Creates a new multi-deep Markov Chain with the depth passed in
/// </summary>
/// <param name="depth">The depth to store information for words. Higher values mean more consistency but less flexibility. Minimum value of three.</param>
public MultiDeepMarkovChain(int depth)
{
if (depth < 3)
throw new ArgumentException("We currently only support Markov Chains 3 or deeper. Sorry :(");
chains = new Dictionary<string, Chain>();
head = new Chain() { text = "[]" };
chains.Add("[]", head);
this.depth = depth;
}
示例12: World
public World()
{
this.thinkers = new Chain<Thinker>();
this.vertices = new List<Vertex>();
this.sectors = new List<Sector>();
this.sidedefs = new List<Sidedef>();
this.linedefs = new List<Linedef>();
this.things = new List<Thing>();
this.blockmap = null;
}
示例13: Calculate
/// <summary>
/// Calculation method.
/// </summary>
/// <param name="chain">
/// Source sequence.
/// </param>
/// <param name="link">
/// Link of intervals in chain.
/// </param>
/// <returns>
/// G+C Ratio value as <see cref="double"/>.
/// </returns>
public double Calculate(Chain chain, Link link)
{
DnaProcessor.CheckDnaAlphabet(chain.Alphabet);
var g = remotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link);
var c = remotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link);
var l = remotenessCalculator.Calculate(chain, link);
return 100 * (g + c) / l;
}
示例14: Calculate
/// <summary>
/// Calculated as base 2 logarithm of multiplication
/// of intervals between nearest elements
/// in congeneric sequence.
/// </summary>
/// <param name="chain">
/// Source sequence.
/// </param>
/// <param name="link">
/// Link of intervals in chain.
/// </param>
/// <returns>
/// Average remoteness <see cref="double"/> value.
/// </returns>
public double Calculate(Chain chain, Link link)
{
double result = 0;
for (int i = 0; i < chain.Alphabet.Cardinality; i++)
{
result += Calculate(chain.CongenericChain(i), link);
}
return result;
}
示例15: Bind
public bool Bind(Chain chain)
{
if (chain != null && this.chain != null && chain != this.chain && !this.chain.OnLinkAdoptedByAnotherChain(this, chain)) {
return false;
}
this.chain = chain;
return true;
}