当前位置: 首页>>代码示例>>C#>>正文


C# Chain类代码示例

本文整理汇总了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);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:26,代码来源:LinearTests.cs

示例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>();
 }
开发者ID:kevinhascode,项目名称:GoGame,代码行数:7,代码来源:IsLegalResponse.cs

示例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);
        }
开发者ID:BlurryRoots,项目名称:UnityUtil,代码行数:28,代码来源:ChainTest.cs

示例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);
            }
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:32,代码来源:FullBlockTestGenerator.cs

示例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;
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:44,代码来源:RemotenessDispersion.cs

示例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);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:34,代码来源:Average.cs

示例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;
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:19,代码来源:AverageRemoteness.cs

示例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();
 }
开发者ID:joe90p,项目名称:Telestrations,代码行数:8,代码来源:GameScoreModels.cs

示例9: EndChainInvolvement

 public void EndChainInvolvement(Chain chain)
 {
     if (Chain != null && Chain == chain)
     {
         Chain.DecrementInvolvement();
         Chain = null;
     }
 }
开发者ID:ronforbes,项目名称:BlockParty1,代码行数:8,代码来源:Block.cs

示例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);
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:21,代码来源:AverageRemotenessATSkew.cs

示例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;
 }
开发者ID:Ricardo1991,项目名称:MarkovChainSentenceGenerator,代码行数:13,代码来源:MultiDeepMarkovChain.cs

示例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;
 }
开发者ID:VenoMpie,项目名称:DoomSharp,代码行数:10,代码来源:World.cs

示例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;
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:22,代码来源:AverageRemotenessGCRatio.cs

示例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;
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:24,代码来源:Depth.cs

示例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;
        }
开发者ID:notrubp,项目名称:Platformer,代码行数:10,代码来源:ChainLink.cs


注:本文中的Chain类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。