public static void Compare(IIonReader it1, IIonReader it2) { while (HasNext(it1, it2)) { IonType t1 = it1.CurrentType; IonType t2 = it2.CurrentType; if (t1 != t2 && !t1.Equals(t2)) { Assert.AreEqual(t1, t2, "ion type"); } if (t1 == IonType.None) { break; } if (it1.IsInStruct) { CompareFieldNames(it1, it2); } CompareAnnotations(it1, it2); CompareAnnotationSymbols(it1, it2); CompareHasAnnotations(it1, it2); bool isNull = it1.CurrentIsNull; Assert.AreEqual(isNull, it2.CurrentIsNull); switch (t1) { case IonType.Null: Assert.IsTrue(it1.CurrentIsNull); Assert.IsTrue(it2.CurrentIsNull); break; case IonType.Bool: case IonType.Int: case IonType.Float: case IonType.Decimal: case IonType.Timestamp: case IonType.String: case IonType.Symbol: case IonType.Blob: case IonType.Clob: CompareScalars(t1, isNull, it1, it2); break; case IonType.Struct: case IonType.List: case IonType.Sexp: it1.StepIn(); it2.StepIn(); Compare(it1, it2); it1.StepOut(); it2.StepOut(); break; default: throw new InvalidOperationException(); } } Assert.IsFalse(HasNext(it1, it2)); }
/// <summary> /// Calculate all possible transition losses that apply to a transition with /// a specific type and cleavage offset, given all of the potential loss permutations /// for the precursor. /// </summary> public static IEnumerable <TransitionLosses> CalcTransitionLosses(IonType type, int cleavageOffset, MassType massType, IEnumerable <IList <ExplicitLoss> > potentialLosses) { // First return no losses yield return(null); if (type.Equals(IonType.custom)) { foreach (var potentialLoss in potentialLosses) { yield return(GetCustomTransitionLosses(potentialLoss, massType)); } } else if (potentialLosses != null) { // Try to avoid allocating a whole list for this, as in many cases // there should be only one loss TransitionLosses firstLosses = null; List <TransitionLosses> allLosses = null; foreach (var losses in potentialLosses) { var tranLosses = CalcTransitionLosses(type, cleavageOffset, massType, losses); if (tranLosses == null || (firstLosses != null && firstLosses.Mass == tranLosses.Mass) || (allLosses != null && allLosses.Contains(l => l.Mass == tranLosses.Mass))) { continue; } if (allLosses == null) { if (firstLosses == null) { firstLosses = tranLosses; } else { allLosses = new List <TransitionLosses> { firstLosses }; firstLosses = null; } } if (allLosses != null) { allLosses.Add(tranLosses); } } // Handle the single losses case first if (firstLosses != null) { yield return(firstLosses); } else if (allLosses != null) { // If more then one set of transition losses return them sorted by mass allLosses.Sort((l1, l2) => Comparer <double> .Default.Compare(l1.Mass, l2.Mass)); foreach (var tranLosses in allLosses) { yield return(tranLosses); } } } }