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


C# Generator.WriteValuesToByteArray方法代码示例

本文整理汇总了C#中Generator.WriteValuesToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# Generator.WriteValuesToByteArray方法的具体用法?C# Generator.WriteValuesToByteArray怎么用?C# Generator.WriteValuesToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Generator的用法示例。


在下文中一共展示了Generator.WriteValuesToByteArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: When_changing_only_single_bit_then_the_id_is_generated_correctly

        public void When_changing_only_single_bit_then_the_id_is_generated_correctly()
        {
            var numberOfGenerators = Math.Pow(2, Generator.NumberOfGeneratorIdBits);
            var target = new byte[8];
            var generator = new Generator((short)(numberOfGenerators - 1), DateTime.Today);

            generator.WriteValuesToByteArray(target, 4398046511103, 8191);
            Assert.Equal(new string('1', 64), GetString(target));

            generator.WriteValuesToByteArray(target, 4398046511103, 8190);
            Assert.Equal(new string('1', 63) + "0", GetString(target));

            generator.WriteValuesToByteArray(target, 4398046511102, 8191);
            Assert.Equal(
                new string('1', Generator.NumberOfTimeBits - 1) + "0" + new string('1', 64 - Generator.NumberOfTimeBits),
                GetString(target));

            generator = new Generator((short)(numberOfGenerators - 2), DateTime.Today);
            generator.WriteValuesToByteArray(target, 4398046511103, 8191);
            Assert.Equal(
                new string('1', 63 - Generator.NumberOfSequenceBits) + "0" + new string('1', Generator.NumberOfSequenceBits),
                GetString(target));

            for (int i = 0; i < numberOfGenerators; i++)
            {
                generator = new Generator((short)i, DateTime.Today);
                generator.WriteValuesToByteArray(target, 0, 0);
                Assert.Equal(new string('0', Generator.NumberOfTimeBits), GetString(target).Substring(0, Generator.NumberOfTimeBits));
                Assert.Equal(new string('0', Generator.NumberOfSequenceBits), GetString(target).Substring(64 - Generator.NumberOfSequenceBits, Generator.NumberOfSequenceBits));

                var m = Convert.ToString(i, 2).PadLeft(Generator.NumberOfGeneratorIdBits, '0');
                Assert.Equal(m, GetString(target).Substring(Generator.NumberOfTimeBits, Generator.NumberOfGeneratorIdBits));
            }
        }
开发者ID:faint32,项目名称:UniqueIdGenerator,代码行数:34,代码来源:GeneratorTests.cs

示例2: When_iterating_through_all_possible_sequences_then_every_generated_id_is_correct

        public void When_iterating_through_all_possible_sequences_then_every_generated_id_is_correct()
        {
            var target = new byte[8];
            var generator = new Generator(0, DateTime.Today);
            var firstPartLength = 64 - Generator.NumberOfSequenceBits;

            for (short i = 0; i < Math.Pow(2, Generator.NumberOfSequenceBits); i++)
            {
                generator.WriteValuesToByteArray(target, 0, i);
                Assert.Equal(new string('0', firstPartLength), GetString(target).Substring(0, firstPartLength));

                var s = Convert.ToString(i, 2).PadLeft(Generator.NumberOfSequenceBits, '0');
                Assert.Equal(s, GetString(target).Substring(firstPartLength, Generator.NumberOfSequenceBits));
            }
        }
开发者ID:faint32,项目名称:UniqueIdGenerator,代码行数:15,代码来源:GeneratorTests.cs

示例3: When_iterating_through_all_possible_generators_then_every_generated_id_is_correct

        public void When_iterating_through_all_possible_generators_then_every_generated_id_is_correct()
        {
            var target = new byte[8];

            for (short i = 0; i < Math.Pow(2, Generator.NumberOfGeneratorIdBits); i++)
            {
                var generator = new Generator(i, DateTime.Today);
                generator.WriteValuesToByteArray(target, 0, 0);
                var s = GetString(target);
                Assert.Equal(new string('0', Generator.NumberOfTimeBits), s.Substring(0, Generator.NumberOfTimeBits));
                Assert.Equal(new string('0', Generator.NumberOfSequenceBits), s.Substring(64 - Generator.NumberOfSequenceBits, Generator.NumberOfSequenceBits));

                var m = Convert.ToString(i, 2).PadLeft(Generator.NumberOfGeneratorIdBits, '0');
                Assert.Equal(m, s.Substring(Generator.NumberOfTimeBits, Generator.NumberOfGeneratorIdBits));
            }
        }
开发者ID:faint32,项目名称:UniqueIdGenerator,代码行数:16,代码来源:GeneratorTests.cs


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