public void AddRangeTest() { int count = 40; int arrayCount = 10; int index = 0; int[] intArray = new int[arrayCount]; var buffer1 = new ChainedBuffer <int>(); for (int i = 0; i < arrayCount; i++) { intArray[i] = i + count; } for (int i = 0; i < count; i++) { buffer1.Add(i); } buffer1.AddRange(intArray); foreach (var buf in buffer1) { Assert.That(buffer1.Contains(index)); ++index; } }
public void CopyToTest() { int count = 40; int arrayIndex = 10; int[] intArray = new int[count + arrayIndex]; var buffer1 = new ChainedBuffer <int>(); bool flag = true; for (int i = 0; i < count; i++) { buffer1.Add(i); } buffer1.CopyTo(intArray, arrayIndex); for (int i = 0; i < count; i++) { if (intArray[i + arrayIndex] != i) { flag = false; } } Assert.That(buffer1.Count + arrayIndex, Is.EqualTo(intArray.Length)); Assert.That(flag); }
/// <summary> /// Builds <see cref="RenameFieldHint"/> for each of renamed field /// of generic type. /// </summary> private void BuildRenameFieldHintsForGenericTypes(IEnumerable <Triplet <string, Type, List <Pair <string, Type> > > > genericTypeMapping, IEnumerable <RenameFieldHint> renameFieldHints, ChainedBuffer <UpgradeHint> rewrittenHints) { var genericTypeDefLookup = ( from triplet in genericTypeMapping group triplet by triplet.Second.GetGenericTypeDefinition() into g select new { Definition = g.Key, Instances = g.ToArray() } ).ToDictionary(g => g.Definition); // Build rename generic type field hints foreach (var hint in renameFieldHints) { var newGenericDefType = hint.TargetType; var instanceGroup = genericTypeDefLookup.GetValueOrDefault(newGenericDefType); if (instanceGroup == null) { continue; } foreach (var triplet in instanceGroup.Instances) { var newGenericArguments = triplet.Third.Select(pair => pair.Second).ToArray(); rewrittenHints.Add(new RenameFieldHint(newGenericDefType.MakeGenericType(newGenericArguments), hint.OldFieldName, hint.NewFieldName)); } } }
private void GetGenericRenameHints( IEnumerable <UpgradeHint> hints, out Dictionary <string, RenameTypeHint> renameTypeHints, out ChainedBuffer <RenameTypeHint> renameGenericTypeHints, out ChainedBuffer <RenameFieldHint> renameFieldHints) { renameTypeHints = new Dictionary <string, RenameTypeHint>(StringComparer.Ordinal); renameGenericTypeHints = new ChainedBuffer <RenameTypeHint>(); renameFieldHints = new ChainedBuffer <RenameFieldHint>(); foreach (var upgradeHint in hints) { if (upgradeHint is RenameTypeHint renameTypeHint) { renameTypeHints.Add(renameTypeHint.OldType, renameTypeHint); if (renameTypeHint.NewType.IsGenericTypeDefinition) { renameGenericTypeHints.Add(renameTypeHint); } } if (upgradeHint is RenameFieldHint renameFieldHint && renameFieldHint.TargetType.IsGenericTypeDefinition) { renameFieldHints.Add(renameFieldHint); } } }
public void ClearTest() { int count = 40; var buffer1 = new ChainedBuffer <string>(); for (int i = 0; i < count; i++) { buffer1.Add(i.ToString()); } buffer1.Clear(); Assert.That(buffer1.Count, Is.EqualTo(0)); buffer1.Add("Hello"); Assert.That(buffer1.Count, Is.EqualTo(1)); Assert.That(buffer1.First(), Is.EqualTo("Hello")); Assert.That(buffer1.Contains("Hello")); }
/// <summary> /// Builds <see cref="RenameTypeHint"/> for generic types. /// </summary> private void BuildRenameHintsForGenericTypes(IList <Triplet <string, Type, List <Pair <string, Type> > > > genericTypeMapping, ChainedBuffer <UpgradeHint> rewrittenHints) { foreach (var triplet in genericTypeMapping) { var oldGenericArguments = triplet.Third.Select(pair => pair.First).ToArray(); var newGenericArguments = triplet.Third.Select(pair => pair.Second).ToArray(); var oldTypeFullName = GetGenericTypeFullName(triplet.First, oldGenericArguments); var newType = triplet.Second.MakeGenericType(newGenericArguments); if (oldTypeFullName != newType.GetFullName()) { rewrittenHints.Add(new RenameTypeHint(oldTypeFullName, newType)); } } }
private static Pair <string>[] AssociateMappedFields(params Pair <StoredFieldInfo>[] fieldsToProcess) { var result = new ChainedBuffer <Pair <StoredFieldInfo> >(); var tasks = new Queue <Pair <StoredFieldInfo> >(); foreach (var task in fieldsToProcess) { tasks.Enqueue(task); } while (tasks.Count > 0) { var task = tasks.Dequeue(); var source = task.First; var target = task.Second; // both fields are primitive -> put to result is types match if (source.IsPrimitive && target.IsPrimitive) { if (source.ValueType != target.ValueType) { return(null); } result.Add(task); continue; } // exactly one of the fields is primitive -> failure if (source.IsPrimitive || target.IsPrimitive) { return(null); } // both fields are not primitive -> recursively process nested fields if (source.Fields.Length != target.Fields.Length) { return(null); } var pairedNestedFields = JoinFieldsByOriginalName(source.Fields, target.Fields); if (pairedNestedFields.Length != source.Fields.Length) { return(null); } foreach (var newTask in pairedNestedFields) { tasks.Enqueue(newTask); } } return(result .SelectToArray(mapping => new Pair <string>(mapping.First.MappingName, mapping.Second.MappingName))); }
public void GetEnumeratorTest() { int count = 40; int index = 0; var buffer1 = new ChainedBuffer <int>(); for (int i = 0; i < count; i++) { buffer1.Add(i); } Assert.AreEqual(count, buffer1.Count); foreach (var buf in buffer1) { Assert.That(buf, Is.EqualTo(index)); ++index; } }
public void ConstructorMaxNodeSizeTest() { int count = 40; int index = 0; int maxNodeSize = 10; var buffer1 = new ChainedBuffer <int>(maxNodeSize); for (int i = 0; i < count; i++) { buffer1.Add(i); } Assert.AreEqual(count, buffer1.Count); foreach (var buf in buffer1) { Assert.That(buf, Is.EqualTo(index)); ++index; } }
public void ContainsTest() { int count = 40; int index = 0; var buffer1 = new ChainedBuffer <int>(); var buffer2 = new ChainedBuffer <string>(); for (int i = 0; i < count; i++) { buffer1.Add(i); buffer2.Add(null); } foreach (var buf in buffer1) { Assert.That(buffer1.Contains(index)); ++index; } Assert.That(buffer2.Contains(null)); }
private void GetGenericRenameHints(IEnumerable <UpgradeHint> hints, out Dictionary <string, RenameTypeHint> renameTypeHints, out ChainedBuffer <RenameTypeHint> renameGenericTypeHints, out ChainedBuffer <RenameFieldHint> renameFieldHints) { renameTypeHints = new Dictionary <string, RenameTypeHint>(); renameGenericTypeHints = new ChainedBuffer <RenameTypeHint>(); renameFieldHints = new ChainedBuffer <RenameFieldHint>(); foreach (var upgradeHint in hints) { var renameTypeHint = upgradeHint as RenameTypeHint; if (renameTypeHint != null) { renameTypeHints.Add(renameTypeHint.OldType, renameTypeHint); if (renameTypeHint.NewType.IsGenericTypeDefinition) { renameGenericTypeHints.Add(renameTypeHint); } } var renameFieldHint = upgradeHint as RenameFieldHint; if (renameFieldHint != null && renameFieldHint.TargetType.IsGenericTypeDefinition) { renameFieldHints.Add(renameFieldHint); } } }