本文整理汇总了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));
}
}
示例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));
}
}
示例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));
}
}