當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。