static void Validate(List <BigLifeRecord> control, ReadWriteValueListVault <BigLifeRecord> test) { if (control.Count != test.GetCurrentCount()) { throw new LogicErrorException("Collections do not have same number of items."); } using var lck = test.RoLock(); for (int i = 0; i < lck.Count; ++i) { BigLifeRecord ctrl = control[i]; if (lck[i] != ctrl) { throw new LogicErrorException( $"Elements at idx {i} are not equal via == - control: [{ctrl}]; test: [{lck[i]}]"); } if (BigLifeRecord.Compare(in lck[i], in ctrl) != 0) { throw new LogicErrorException( $"Elements at idx {i} are not equal via compare - control: [{ctrl}]; test: [{lck[i]}]"); } if (lck[i].GetHashCode() != ctrl.GetHashCode()) { throw new LogicErrorException( $"Elements at idx {i} do not return same hash code - control: [{ctrl}]; test: [{lck[i]}]"); } } }
private protected CafeBabeGameThread([NotNull] ReadWriteValueListVault <UInt256> vault, [NotNull] IOutputHelper helper) { _concreteType = new LocklessConcreteType(this); _valueList = vault ?? throw new ArgumentNullException(nameof(vault)); _t = new LocklessWriteOnce <Thread>(InitThread); _helper = helper ?? throw new ArgumentNullException(nameof(helper)); }
CreateRandomBigLifeRecords(int count) { if (count < 0) { throw new ArgumentNegativeException <int>(nameof(count), count); } List <BigLifeRecord> blr = new List <BigLifeRecord>(count); while (blr.Count < count) { blr.Add(GetRandomBigLifeRecordData()); } VsEnumerableWrapper <BigLifeRecord> ctrl = VsEnumerableWrapper <BigLifeRecord> .FromIEnumerable(blr); ReadWriteValueListVault <BigLifeRecord> tst = new ReadWriteValueListVault <BigLifeRecord>(ctrl); Validate(blr, tst); return(blr, tst);
protected abstract ArbiterThread InitArbiterThread([NotNull] ReadWriteValueListVault <UInt256> vault, [NotNull] IOutputHelper outputHelper);
protected abstract WriterThread InitWriterThread([NotNull] ReadWriteValueListVault <UInt256> vault, [NotNull] IOutputHelper outputHelper, in UInt256 favoriteNumber, [NotNull] WriterThreadBeginToken beginToken);
/// <summary> /// CTOR /// </summary> /// <param name="vault">the vault</param> /// <param name="helper">the output helper</param> /// <exception cref="ArgumentNullException"><paramref name="vault"/> or <paramref name="helper"/> was null.</exception> public ArbiterThread([NotNull] ReadWriteValueListVault <UInt256> vault, [NotNull] IOutputHelper helper) : base( vault, helper) { }
ImmutableArray <BigLifeRecord> Present, ImmutableArray <BigLifeRecord> NotPresent) CreateSortAndSetTestData( int tstControlCount, int numPresentSamples, int numNotPresent) { if (tstControlCount < 1) { throw new ArgumentNotPositiveException <int>(nameof(tstControlCount), tstControlCount); } if (numPresentSamples >= tstControlCount || numPresentSamples < 1) { throw new ArgumentOutOfRangeException(nameof(numPresentSamples), numPresentSamples, @$ "Parameter must be positive and less than {nameof(tstControlCount)}."); } if (numNotPresent >= tstControlCount || numNotPresent < 1) { throw new ArgumentOutOfRangeException(nameof(numNotPresent), numNotPresent, @$ "Parameter must be positive and less than {nameof(tstControlCount)}."); } SortedSet <BigLifeRecord> bigLifeRecords = new SortedSet <BigLifeRecord>(GetRandomRecords(tstControlCount * 2)); while (bigLifeRecords.Count < tstControlCount * 2) { bigLifeRecords.Add(_rgen.GetRandomBigLifeRecordData()); } List <BigLifeRecord> control = new List <BigLifeRecord>(bigLifeRecords.Take(tstControlCount)); _rgen.Shuffle <List <BigLifeRecord>, BigLifeRecord>(control); var notPresent = bigLifeRecords.Skip(tstControlCount).Take(numNotPresent).ToList(); List <BigLifeRecord> present = new List <BigLifeRecord>(control.Take(numPresentSamples)); _rgen.Shuffle <List <BigLifeRecord>, BigLifeRecord>(notPresent); bigLifeRecords.Clear(); HashSet <BigLifeRecord> controlSet = new HashSet <BigLifeRecord>(control); bool allInPresentInControl = controlSet.IsProperSupersetOf(present); bool noneInControl = !controlSet.Overlaps(notPresent) && !(new HashSet <BigLifeRecord>(notPresent)).Overlaps(present); controlSet.Clear(); if (!allInPresentInControl || !noneInControl) { throw new Exception("Logic error in setting up test data!"); } var vault = new ReadWriteValueListVault <BigLifeRecord>(VsEnumerableWrapper <BigLifeRecord> .FromIEnumerable(control)); using var lck = vault.RoLock(); if (lck.Count != control.Count) { throw new Exception("vault count != control count."); } int ctrlCount = 0; foreach (ref readonly var record in lck) { if (record != control[ctrlCount++]) { throw new Exception($"itm at idx {ctrlCount - 1} not equal."); } } return(control, vault, present.ToImmutableArray(), notPresent.ToImmutableArray()); }
/// <summary> ///CTOR /// </summary> /// <param name="vault">vault protecting the string</param> /// <param name="helper">helper for i/o</param> /// <param name="favoriteNumber">number it writes</param> /// <param name="token">Start token</param> /// <param name="minWrites">min writes</param> /// <param name="maxWrites">max writes</param> /// <exception cref="ArgumentNullException"><paramref name="vault"/> or <paramref name="helper"/> /// or <paramref name="token"/> was <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">Min writes was negative. Or max writes did not exceed min writes /// by at least three.</exception> internal WriterThread([NotNull] ReadWriteValueListVault <UInt256> vault, [NotNull] IOutputHelper helper, in UInt256 favoriteNumber, [NotNull] WriterThreadBeginToken token, int minWrites = DefaultMinWrites,