How to use GenA class of B package

Best Nunit code snippet using B.GenA

TypeNameDifferenceTests.cs

Source:TypeNameDifferenceTests.cs Github

copy

Full Screen

...61 }62 }63 namespace A64 {65 class GenA<T>66 { }67 class GenB<T>68 { }69 class GenC<T, R>70 { }71 namespace B72 {73 class GenX<T>74 { }75 class GenY<T>76 { }77 }78 }79 namespace B80 {81 class GenA<T>82 { }83 class GenB<T>84 { }85 class GenC<T, R>86 { }87 namespace B88 {89 class GenX<T>90 { }91 class GenY<T>92 { }93 }94 }95 #endregion96 public class TypeNameDifferenceTests97 {98 #region Mock types99 class Dummy100 {101 internal readonly int value;102 public Dummy(int value)103 {104 this.value = value;105 }106 public override string ToString()107 {108 return "Dummy " + value;109 }110 }111 class Dummy1112 {113 internal readonly int value;114 public Dummy1(int value)115 {116 this.value = value;117 }118 public override string ToString()119 {120 return "Dummy " + value;121 }122 }123 class DummyGenericClass<T>124 {125 private object _obj;126 public DummyGenericClass(object obj)127 {128 _obj = obj;129 }130 public override string ToString()131 {132 return _obj.ToString();133 }134 }135 #endregion136 TypeNameDifferenceResolver _differenceGetter;137 [SetUp]138 public void TestSetup()139 {140 _differenceGetter = new TypeNameDifferenceResolver();141 }142 private void TestShortenedNameDifference(object objA, object objB, string expectedA, string expectedB)143 {144 string actualA, actualB;145 _differenceGetter.ResolveTypeNameDifference(146 objA, objB, out actualA, out actualB);147 Assert.That(actualA, Is.EqualTo(expectedA));148 Assert.That(actualB, Is.EqualTo(expectedB));149 }150 [Test]151 public void TestResolveTypeNameDifferenceNonGenericDifferingTypes()152 {153 TestShortenedNameDifference(154 new Dummy(1),155 new Dummy1(1),156 "TypeNameDifferenceTests+Dummy",157 "TypeNameDifferenceTests+Dummy1");158 }159 [Test]160 public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypes()161 {162 TestShortenedNameDifference(163 new Dummy(1),164 new Dummy(1),165 "TypeNameDifferenceTests+Dummy",166 "TypeNameDifferenceTests+Dummy");167 }168 [Test]169 public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypesSingularDiffNamespace()170 {171 TestShortenedNameDifference(172 new DifferingNamespace1.Dummy(1),173 new Dummy(1),174 "Dummy",175 "TypeNameDifferenceTests+Dummy");176 }177 [Test]178 public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypesBothDiffNamespace()179 {180 TestShortenedNameDifference(181 new DifferingNamespace1.Dummy(1),182 new DifferingNamespace2.Dummy(1),183 "DifferingNamespace1.Dummy",184 "DifferingNamespace2.Dummy");185 }186 [Test]187 public void TestResolveTypeNameDifferenceGeneric()188 {189 TestShortenedNameDifference(190 new DummyGenericClass<Dummy1>(new Dummy(1)),191 new DummyGenericClass<Dummy>(new Dummy(1)),192 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy1]",193 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");194 }195 [Test]196 public void TestResolveTypeNameDifferenceGenericDifferingNamespaces()197 {198 TestShortenedNameDifference(199 new DummyGenericClass<Dummy>(new Dummy(1)),200 new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),201 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]",202 "TypeNameDifferenceTests+DummyGenericClass`1[Dummy]");203 TestShortenedNameDifference(204 new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),205 new DummyGenericClass<Dummy>(new Dummy(1)),206 "TypeNameDifferenceTests+DummyGenericClass`1[Dummy]",207 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");208 TestShortenedNameDifference(209 new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),210 new DummyGenericClass<DifferingNamespace2.Dummy>(new DifferingNamespace2.Dummy(1)),211 "TypeNameDifferenceTests+DummyGenericClass`1[DifferingNamespace1.Dummy]",212 "TypeNameDifferenceTests+DummyGenericClass`1[DifferingNamespace2.Dummy]");213 }214 [Test]215 public void TestResolveTypeNameDifferenceGenericDifferentAmountGenericParams()216 {217 TestShortenedNameDifference(218 new DummyGenericClass<Dummy>(new Dummy(1)),219 new KeyValuePair<int, string>(1, ""),220 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]",221 "KeyValuePair`2[Int32,String]");222 TestShortenedNameDifference(223 new KeyValuePair<int, string>(1, ""),224 new DummyGenericClass<Dummy>(new Dummy(1)),225 "KeyValuePair`2[Int32,String]",226 "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");227 }228 [Test]229 public void TestResolveNameDifferenceOneIsGenericOtherIsNot()230 {231 TestShortenedNameDifference(232 new DummyGenericClass<Dummy>(new Dummy(1)),233 new Dummy(1),234 "DummyGenericClass`1[Dummy]",235 "Dummy");236 TestShortenedNameDifference(237 new Dummy(1),238 new DummyGenericClass<Dummy>(new Dummy(1)),239 "Dummy",240 "DummyGenericClass`1[Dummy]");241 TestShortenedNameDifference(242 new KeyValuePair<string, int>("str", 0),243 new Dummy(1),244 "KeyValuePair`2[String,Int32]",245 "Dummy");246 TestShortenedNameDifference(247 new Dummy(1),248 new KeyValuePair<string, int>("str", 0),249 "Dummy",250 "KeyValuePair`2[String,Int32]");251 TestShortenedNameDifference(252 new Dummy(1),253 new A.GenA<B.GenA<B.GenC<string, int>>>(),254 "Dummy",255 "GenA`1[GenA`1[GenC`2[String,Int32]]]");256 TestShortenedNameDifference(257 new A.GenA<B.GenA<B.GenC<string, int>>>(),258 new Dummy(1),259 "GenA`1[GenA`1[GenC`2[String,Int32]]]",260 "Dummy");261 }262 [Test]263 public void TestNestedGenerics()264 {265 TestShortenedNameDifference(266 new DifferingNamespace1.DummyGeneric<List<string>>(new List<string>()),267 new DifferingNamespace1.DummyGeneric<IEnumerable<string>>(new List<string>()),268 "DummyGeneric`1[List`1[String]]",269 "DummyGeneric`1[IEnumerable`1[String]]");270 TestShortenedNameDifference(271 new DifferingNamespace1.DummyGeneric<IEnumerable<string>>(new List<string>()),272 new DifferingNamespace1.DummyGeneric<List<string>>(new List<string>()),273 "DummyGeneric`1[IEnumerable`1[String]]",274 "DummyGeneric`1[List`1[String]]");275 TestShortenedNameDifference(276 new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>>(new KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>()),277 new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>>(new KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>()),278 "DummyGeneric`1[KeyValuePair`2[DifferingNamespace1.Dummy,DifferingNamespace2.Dummy]]",279 "DummyGeneric`1[KeyValuePair`2[DifferingNamespace2.Dummy,DifferingNamespace1.Dummy]]");280 TestShortenedNameDifference(281 new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>>(new KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>()),282 new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>>(new KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>()),283 "DummyGeneric`1[KeyValuePair`2[DifferingNamespace2.Dummy,DifferingNamespace1.Dummy]]",284 "DummyGeneric`1[KeyValuePair`2[DifferingNamespace1.Dummy,DifferingNamespace2.Dummy]]");285 TestShortenedNameDifference(286 new A.GenA<A.B.GenX<int>>(),287 new B.GenA<A.B.GenX<short>>(),288 "A.GenA`1[GenX`1[Int32]]",289 "B.GenA`1[GenX`1[Int16]]");290 TestShortenedNameDifference(291 new B.GenA<A.B.GenX<short>>(), 292 new A.GenA<A.B.GenX<int>>(),293 "B.GenA`1[GenX`1[Int16]]",294 "A.GenA`1[GenX`1[Int32]]");295 TestShortenedNameDifference(296 new A.GenC<int, string>(),297 new B.GenC<int, A.GenA<string>>(),298 "A.GenC`2[Int32,String]",299 "B.GenC`2[Int32,GenA`1[String]]");300 TestShortenedNameDifference(301 new A.GenA<A.GenC<string, int>>(),302 new B.GenC<A.GenA<List<int>>, B.GenC<string, int>>(),303 "GenA`1[GenC`2[String,Int32]]",304 "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,Int32]]");305 TestShortenedNameDifference(306 new B.GenC<A.GenA<List<int>>, B.GenC<string, int>>(),307 new A.GenA<A.GenC<string, int>>(),308 "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,Int32]]",309 "GenA`1[GenC`2[String,Int32]]");310 TestShortenedNameDifference(311 new B.GenC<A.GenA<List<int>>, B.GenC<string, B.GenC<string, int>>>(),312 new A.GenA<B.GenC<string, B.GenC<string,int>>>(),313 "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,GenC`2[String,Int32]]]",314 "GenA`1[GenC`2[String,GenC`2[String,Int32]]]");315 TestShortenedNameDifference(316 new A.GenA<B.GenC<string, B.GenC<string, int>>>(),317 new B.GenC<A.GenA<List<int>>, B.GenC<string, B.GenC<string, int>>>(),318 "GenA`1[GenC`2[String,GenC`2[String,Int32]]]",319 "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,GenC`2[String,Int32]]]");320 }321 [Test]322 public void TestIsObjectInstanceGeneric()323 {324 var notGeneric = new DifferingNamespace1.Dummy(1);325 Assert.False(_differenceGetter.IsTypeGeneric(notGeneric.GetType()));326 var generic = new DifferingNamespace1.DummyGeneric<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1));327 Assert.That(_differenceGetter.IsTypeGeneric(generic.GetType()));328 }329 [Test]330 public void TestGetTopLevelGenericName()331 {332 var generic = new DifferingNamespace1.DummyGeneric<int>(1).GetType();333 var expected = "NUnit.Framework.Internal.DifferingNamespace1.DummyGeneric`1";334 var actual = _differenceGetter.GetGenericTypeName(generic);335 Assert.AreEqual(expected, actual);336 }337 [Test]338 public void TestGetTopLevelGenericNameThrowsWhenNotGeneric()339 {340 var notGeneric = new object().GetType();341 Assert.Throws<ArgumentException>(() => _differenceGetter.GetGenericTypeName(notGeneric));342 }343 [Test]344 public void TestReconstructShortenedGenericTypeName()345 {346 var expected = "KeyValuePair`2[String,Int32]";347 var actual = _differenceGetter.ReconstructGenericTypeName(348 "KeyValuePair`2",349 new List<string>() { "String", "Int32" });350 Assert.AreEqual(expected, actual);351 }352 private void TestShortenTypeNames(object objA, object objB, string shortenedA, string shortenedB)353 {354 string actualA, actualB;355 _differenceGetter.ShortenTypeNames(objA.GetType(), objB.GetType(), out actualA, out actualB);356 Assert.AreEqual(shortenedA, actualA);357 Assert.AreEqual(shortenedB, actualB);358 }359 [Test]360 public void TestShortenTypeNamesDifferingNamespace()361 {362 TestShortenTypeNames(363 new DifferingNamespace1.Dummy(1),364 new DifferingNamespace2.Dummy(1),365 "DifferingNamespace1.Dummy",366 "DifferingNamespace2.Dummy");367 }368 private void TestShortenGenericTopLevelTypeNames(object objA, object objB, string shortenedA, string shortenedB)369 {370 string actualA, actualB;371 _differenceGetter.GetShortenedGenericTypes(objA.GetType(), objB.GetType(), out actualA, out actualB);372 Assert.AreEqual(shortenedA, actualA);373 Assert.AreEqual(shortenedB, actualB);374 }375 [Test]376 public void TestShortenGenericTopLevelTypes()377 {378 TestShortenGenericTopLevelTypeNames(379 new A.GenA<int>(),380 new B.GenA<int>(),381 "A.GenA`1",382 "B.GenA`1");383 TestShortenGenericTopLevelTypeNames(384 new KeyValuePair<string, int>(),385 new KeyValuePair<int, string>(),386 "KeyValuePair`2",387 "KeyValuePair`2");388 }389 private void TestFullyShortenTypeName(Type type, string expectedOutput)390 {391 string actual = _differenceGetter.FullyShortenTypeName(type);392 Assert.AreEqual(expectedOutput, actual);393 }394 [Test]395 public void TestFullyShortenTypeName()396 {397 TestFullyShortenTypeName(398 new A.GenA<A.GenA<int>>().GetType(),399 "GenA`1[GenA`1[Int32]]");400 TestFullyShortenTypeName(401 new A.GenC<B.GenA<int>, A.GenA<int>>().GetType(),402 "GenC`2[GenA`1[Int32],GenA`1[Int32]]");403 }404 }405}...

Full Screen

Full Screen

generics-sharing.2.cs

Source:generics-sharing.2.cs Github

copy

Full Screen

...70 public GenStruct<T> valueIMethod (int x) {71 return new GenStruct<T> (x);72 }73}74public class GenA<T> {75 public static T[] arr;76 static GenA () {77 arr = new T [3];78 }79 public GenA () {}80 public GenA<T> newGen () {81 return new GenA<T> ();82 }83 public GenA<int> newGenInt () {84 return new GenA<int> ();85 }86 public int getGenField () {87 return GenB<ClassA>.field;88 }89 public int getNonGenField () {90 return NonGen.field;91 }92 public int getGenStructStaticField () {93 return GenStruct<T>.staticField;94 }95 public T[] getArr () {96 return arr;97 }98 public T[] newArr () {99 return new T [3];100 }101 public GenA<T>[] newSelfArr () {102 return new GenA<T> [3];103 }104 public GenB<GenB<T>>[] newArrNested () {105 /*106 GenB<GenB<T>>[] arr = null;107 for (int i = 0; i < 10000000; ++i)108 arr = new GenB<GenB<T>> [3];109 */110 return new GenB<GenB<T>> [3];111 }112 public int hash (T obj) {113 return obj.GetHashCode ();114 }115 public T ident (T obj) {116 return obj;117 }118 public T cast (Object obj) {119 return (T)obj;120 }121 public GenStruct<T> structCast (Object obj) {122 return (GenStruct<T>)obj;123 }124 public Type ldtokenT () {125 return typeof (T);126 }127 public Type ldtokenIGenT () {128 return typeof (IGen<T>);129 }130 public Type ldtokenGenAIGenT () {131 return typeof (GenA<IGen<T>>);132 }133 public Type ldtokenGenB () {134 return typeof (GenB<>);135 }136 public GenStruct<T>? makeNullable (Object obj) {137 return (GenStruct<T>?)obj;138 }139 public object unmakeNullable (GenStruct<T>? obj) {140 return (object)obj;141 }142 public void except () {143 try {144 NonGen.doThrow ();145 }146 catch (GenExc<T>) {147 //Console.WriteLine("exception thrown");148 }149 }150 public static void staticExcept () {151 try {152 NonGen.doThrow ();153 }154 catch (GenExc<T>) {155 Console.WriteLine("exception thrown and caught");156 }157 }158 public static int staticField = 54321;159 public static int staticMethod () {160 return staticField;161 }162 public static int staticMethodCaller () {163 return staticMethod ();164 }165 public static float staticFloatField = 1.0f;166 public static float staticFloatMethod () {167 return staticFloatField;168 }169 public static int staticBiCaller (int x) {170 return GenBi<int,T>.staticMethod (x);171 }172 public static void staticBiVoidCaller (int x) {173 GenBi<int,T>.staticVoidMethod (x);174 }175 public static float staticBiFloatCaller () {176 return GenBi<int,T>.staticFloatMethod ();177 }178 public static GenStruct<T> staticBiValueCaller (int x) {179 return GenBi<int,T>.staticValueMethod (x);180 }181 public static int staticSharedBiCaller (int x) {182 return GenBi<T,T>.staticMethod (x);183 }184 public static void staticSharedBiVoidCaller (int x) {185 GenBi<T,T>.staticVoidMethod (x);186 }187 public static float staticSharedBiFloatCaller () {188 return GenBi<T,T>.staticFloatMethod ();189 }190 public static GenStruct<T> staticSharedBiValueCaller (int x) {191 return GenBi<T,T>.staticValueMethod (x);192 }193 public static long staticBiLongCaller (long x) {194 return GenBi<int, T>.staticLongMethod (x);195 }196 public int structCaller (int x) {197 GenStruct<GenA<T>> gs = new GenStruct<GenA<T>> (123);198 return gs.method (x);199 }200 public T[] callInterface (IGen<T> ig) {201 return ig.iMethod ();202 }203 public void callVoidInterface (IGen<T> ig, int x) {204 ig.voidIMethod (x);205 }206 public long callLongInterface (IGen<T> ig, long x) {207 return ig.longIMethod (x);208 }209 public float callFloatInterface (IGen<T> ig) {210 return ig.floatIMethod ();211 }212 public GenStruct<T> callValueInterface (IGen<T> ig, int x) {213 return ig.valueIMethod (x);214 }215}216public class GenB<T> {217 public static int field = 123;218}219public class GenC<T> {220 public static int field ;221 static GenC () {222 field = 1234;223 }224}225public class StaticTest<T> {226 static int stat;227 public StaticTest (int x) {228 stat = x;229 }230 public int getStat () {231 return stat;232 }233 public int getOtherStat () {234 return StaticTest<Object>.stat;235 }236 public int getGenCStat () {237 return GenC<T>.field;238 }239}240public class GenADeriv<T> : GenA<T> {241 public static int otherField = 123;242}243public class GenABDeriv<T> : GenA<GenB<T>> {244 public T[] newDerivArr () {245 return new T [3];246 }247}248public class NonGenUser<T> where T : NonGen {249 public int getNonGenField () {250 return NonGen.field;251 }252}253public class AccessTest<T> {254 private static int field = 123;255 public int getOtherField () {256 return AccessTest<int>.field;257 }258}259public class VirtualTest<T> {260 public virtual T[] newArr () {261 return new T [3];262 }263}264public class VirtualTestDeriv<T> : VirtualTest<T> {265 public override T[] newArr () {266 return new T [4];267 }268}269public class VirtualTestCaller<T> {270 public T[] doCall (VirtualTest<T> vt) {271 return vt.newArr ();272 }273}274public class MyCons<T> {275 public T car;276 public MyCons<T> cdr;277 public static void printCar (T _car) {278 Console.WriteLine ("car " + _car.ToString () /* + " cdr " + _cdr.ToString () */);279 }280 public MyCons (T _car, MyCons<T> _cdr) {281 //printCar (_car);282 car = _car; cdr = _cdr;283 }284 public static MyCons<T> returnList (MyCons<T> l) { return l; }285 public static MyCons<T> returnCdr (MyCons<T> cons) { return returnList(cons.cdr); }286}287public class MyPair<N,M> {288 public N n;289 public M m;290 public MyPair (N _n, M _m) { n = _n; m = _m; }291}292public class MyDict<N,M> {293 public MyPair<N,M> p;294 public MyDict (N n, M m) { p = new MyPair<N,M> (n, m); }295}296public class RGCTXTest<T> {297 public GenA<T>[] newAArr () {298 return new GenA<T> [3];299 }300}301public class RGCTXTestSubA<T> : RGCTXTest<T> {302 public GenB<T>[] newBArr () {303 return new GenB<T> [3];304 }305}306public class RGCTXTestSubB<T> : RGCTXTest<T> {307 public GenC<T>[] newCArr () {308 return new GenC<T> [3];309 }310}311public class RGCTXTestSubASub : RGCTXTestSubA<ClassA> {312}313public class RGCTXTestSubASubSub<T> : RGCTXTestSubASub {314 public GenC<T>[] newCArr () {315 return new GenC<T> [3];316 }317}318public class main {319 delegate void ActionDelegate ();320 static bool haveError = false;321 static void error (string message) {322 haveError = true;323 Console.WriteLine (message);324 }325 static void typeCheck (String method, Object obj, Type t) {326 if (obj.GetType () != t)327 error ("object from " + method + " should have type " + t.ToString () + " but has type " + obj.GetType ().ToString ());328 }329 static int callStaticMethod<T> () {330 return GenA<T>.staticMethod ();331 }332 static void checkException<T> (String method, ActionDelegate action) where T : Exception {333 try {334 try {335 action ();336 } catch (T) {337 return;338 }339 } catch (Exception exc) {340 error ("method " + method + " should have thrown " + typeof (T).ToString () + " but did throw " + exc);341 }342 }343 public static void work<T> (T obj, bool mustCatch) {344 EqualityComparer<T> comp = EqualityComparer<T>.Default;345 GenA<T> ga = new GenA<T> ();346 typeCheck ("newGen", ga.newGen (), typeof (GenA<T>));347 typeCheck ("newGenInt", ga.newGenInt (), typeof (GenA<int>));348 typeCheck ("getArr", ga.getArr (), typeof (T[]));349 typeCheck ("newArr", ga.newArr (), typeof (T[]));350 typeCheck ("newSelfArr", ga.newSelfArr (), typeof (GenA<T>[]));351 //ga.newArrNested ();352 typeCheck ("newArrNested", ga.newArrNested (), typeof (GenB<GenB<T>>[]));353 if (ga.getGenField () != 123)354 error ("getGenField");355 if (ga.getNonGenField () != 123)356 error ("getNonGenField");357 GenStruct<T>.staticField = 321;358 if (ga.getGenStructStaticField () != 321)359 error ("getGenStructStaticField");360 GenStruct<T>.staticField = -1;361 ga.hash (obj);362 if (!comp.Equals (ga.ident (obj), obj))363 error ("ident");364 if (!comp.Equals (ga.cast (obj), obj))365 error ("cast");366 if (typeof (T).IsValueType) {367 checkException<NullReferenceException> ("cast null value", delegate { ga.cast (null); });368 } else {369 if (ga.cast (null) != null)370 error ("cast null");371 }372 GenStruct<T> genstructt = new GenStruct<T> (453);373 if (ga.structCast ((object)genstructt).field != 453)374 error ("structCast");375 checkException<NullReferenceException> ("structCast null", delegate { ga.structCast (null); });376 if (ga.makeNullable ((object)genstructt).Value.field != 453)377 error ("makeNullable");378 if (ga.makeNullable (null) != null)379 error ("makeNullable null");380 if (ga.ldtokenT () != typeof (T))381 error ("ldtokenT");382 if (ga.ldtokenIGenT () != typeof (IGen<T>))383 error ("ldtokenIGenT");384 if (ga.ldtokenGenAIGenT () != typeof (GenA<IGen<T>>))385 error ("ldtokenGenAIGenT");386 if (ga.ldtokenGenB () != typeof (GenB<>))387 error ("ldtokenGenB");388 if (callStaticMethod<T> () != 54321)389 error ("staticMethod");390 GenBi<int,T>.field = 123;391 if (GenA<T>.staticBiCaller (123) != 246)392 error ("staticBiCaller");393 GenA<T>.staticBiVoidCaller (1234);394 if (GenBi<int,T>.field != 1234)395 error ("staticBiVoidCaller");396 if (GenA<T>.staticBiFloatCaller () != 1.0f)397 error ("staticBiFloatCaller");398 if (GenA<T>.staticBiLongCaller (123) != 123 + 1234)399 error ("staticBiLongCaller");400 GenStruct<T> gs = GenA<T>.staticBiValueCaller (987);401 if (gs.field != 987)402 error ("staticBiValueCaller");403 GenBi<T,T>.field = 123;404 if (GenA<T>.staticSharedBiCaller (123) != 246)405 error ("staticSharedBiCaller");406 GenA<T>.staticSharedBiVoidCaller (1234);407 if (GenBi<T,T>.field != 1234)408 error ("staticSharedBiVoidCaller");409 if (GenA<T>.staticSharedBiFloatCaller () != 1.0f)410 error ("staticSharedBiFloatCaller");411 GenStruct<T> gss = GenA<T>.staticSharedBiValueCaller (987);412 if (gss.field != 987)413 error ("staticSharedBiValueCaller");414 IntVoidDelegate ivdel = new IntVoidDelegate (GenA<T>.staticMethod);415 if (ivdel () != 54321)416 error ("staticMethod delegate");417 Type gatype = typeof (GenA<T>);418 MethodInfo staticMethodInfo = gatype.GetMethod ("staticMethod");419 if ((Convert.ToInt32 (staticMethodInfo.Invoke (null, null))) != 54321)420 error ("staticMethod reflection");421 if (GenA<T>.staticMethodCaller () != 54321)422 error ("staticMethodCaller");423 if (GenA<T>.staticFloatMethod () != 1.0)424 error ("staticFloatMethod");425 if (ga.structCaller (234) != 357)426 error ("structCaller");427 IGenImpl<T> igi = new IGenImpl<T> ();428 typeCheck ("callInterface", ga.callInterface (igi), typeof (T[]));429 if (ga.callLongInterface (igi, 345) != 346)430 error ("callLongInterface");431 GenStruct<T> gst = ga.callValueInterface (igi, 543);432 if (gst.field != 543)433 error ("callValueInterface");434 ga.callVoidInterface (igi, 654);435 if (igi.field != 654)436 error ("callVoidInterface");437 if (ga.callFloatInterface (igi) != 1.0f)438 error ("callFloatInterface");439 new GenADeriv<T> ();440 if (mustCatch) {441 checkException<GenExc<ClassA>> ("except", delegate { ga.except (); });442 checkException<GenExc<ClassA>> ("staticExcept", delegate { GenA<T>.staticExcept (); });443 } else {444 ga.except ();445 GenA<T>.staticExcept ();446 }447 MyDict<T, ClassB> dtb = new MyDict<T, ClassB> (obj, new ClassB ());448 typeCheck ("MyPair", dtb.p, typeof (MyPair<T, ClassB>));449 GenABDeriv<T> gabd = new GenABDeriv<T> ();450 typeCheck ("GenABDeriv.newArr", gabd.newArr (), typeof (GenB<T>[]));451 typeCheck ("GenABDeriv.newDerivArr", gabd.newDerivArr (), typeof (T[]));452 RGCTXTest<T> rt = new RGCTXTest<T> ();453 RGCTXTestSubA<T> rtsa = new RGCTXTestSubA<T> ();454 RGCTXTestSubB<T> rtsb = new RGCTXTestSubB<T> ();455 RGCTXTestSubASub rtsas = new RGCTXTestSubASub ();456 RGCTXTestSubASubSub<T> rtsass = new RGCTXTestSubASubSub<T> ();457 typeCheck ("rtsass.newCArr", rtsass.newCArr (), typeof (GenC<T>[]));458 typeCheck ("rgsa.newBArr", rtsa.newBArr (), typeof (GenB<T>[]));459 typeCheck ("rg.newAArr", rt.newAArr (), typeof (GenA<T>[]));460 typeCheck ("rgsb.newCArr", rtsb.newCArr (), typeof (GenC<T>[]));461 /* repeat all for each class */462 typeCheck ("rtsass.newCArr", rtsass.newCArr (), typeof (GenC<T>[]));463 typeCheck ("rtsass.newBArr", rtsass.newBArr (), typeof (GenB<ClassA>[]));464 typeCheck ("rtsass.newAArr", rtsass.newAArr (), typeof (GenA<ClassA>[]));465 typeCheck ("rtsas.newBArr", rtsas.newBArr (), typeof (GenB<ClassA>[]));466 typeCheck ("rtsas.newAArr", rtsas.newAArr (), typeof (GenA<ClassA>[]));467 typeCheck ("rtsa.newBArr", rtsa.newBArr (), typeof (GenB<T>[]));468 typeCheck ("rtsa.newAArr", rtsa.newAArr (), typeof (GenA<T>[]));469 typeCheck ("rtsb.newCArr", rtsb.newCArr (), typeof (GenC<T>[]));470 typeCheck ("rtsb.newAArr", rtsb.newAArr (), typeof (GenA<T>[]));471 typeCheck ("rt.newAArr", rt.newAArr (), typeof (GenA<T>[]));472 }473 public static void virtualTest<T> (VirtualTest<T> vt, int len) {474 VirtualTestCaller<T> vtc = new VirtualTestCaller<T> ();475 T[] arr = vtc.doCall (vt);476 typeCheck ("virtualTest", arr, typeof (T[]));477 if (arr.Length != len)478 error ("virtualTest length");479 }480 public static void listTest () {481 MyCons<string> ls = new MyCons<string> ("abc", null);482 MyCons<string> cdr = MyCons<string>.returnCdr (ls);483 if (cdr != null)484 error ("cdr is not null");485 }486 public static int Main ()487 {488 work<ClassA> (new ClassA (), false);489 work<ClassB> (new ClassB (), true);490 work<ClassB> (new ClassB (), true);491 work<ClassC> (new ClassC (), true);492 work<GenA<ClassA>> (new GenA<ClassA> (), true);493 work<int[]> (new int[3], true);494 work<int> (123, true);495 work<int?> (123, true);496 work<GenStruct<ClassA>?> (new GenStruct<ClassA> (123), true);497 work<GenStruct<ClassA>?> (null, true);498 StaticTest<ClassA> sa = new StaticTest<ClassA> (1234);499 StaticTest<ClassB> sb = new StaticTest<ClassB> (2345);500 if (sa.getStat () != 1234)501 error ("getStat");502 if (sb.getStat () != 2345)503 error ("getStat");504 if (sa.getOtherStat () != 0)505 error ("getOtherStat");506 if (sa.getGenCStat () != 1234)...

Full Screen

Full Screen

Gaa.cs

Source:Gaa.cs Github

copy

Full Screen

...16 {17 Random rand = new Random();18 int N = 10;19 static int size = 10;20 public List<int> GenA = new List<int>();21 public List<int> GenC = new List<int>();22 public List<int> GenB = new List<int>();23 public int ostA = size;24 public int ostB = size;25 public int ostC = size;26 public Xromossomi(int i)27 {28 ostA = i;29 ostB = i;30 ostC = i;31 }32 public Xromossomi() { }33 }3435 Xromossomi nach()36 {373839 Xromossomi xrom = new Xromossomi();40 int buff = 0;4142 for (int i = 0; i < N / 2 - 1; i++)43 {44 if (xrom.ostA == 2)45 {46 buff = 2;47 xrom.ostA = 0;48 }49 else50 if (xrom.ostA == 1)51 {52 xrom.GenA[xrom.GenA.Count - 1]++;53 xrom.ostA = 0;54 buff = 0;55 }56 else57 if (xrom.ostA == 0)58 buff = 0;59 else60 xrom.ostA -= buff = rand.Next(2, xrom.ostA);61 xrom.GenA.Add(buff);62 }63 xrom.GenA.Add(xrom.ostA);64 //65 int s = N % 3 == 2 ? N / 3 + 1 : N / 3;66 int t = N % 3 == 1 || N % 3 == 2 ? N / 3 + 1 : N / 3;67 buff = 0;68 for (int i = 0; i < N / 2 - 1; i++)69 {70 if (xrom.ostB == 0 && 10 == xrom.GenA.Sum() && xrom.GenA[2] != 0)71 {7273 }7475 if (xrom.ostB == 2)76 {77 buff = 2;78 xrom.ostB = 0;79 }80 else81 if (xrom.ostB == 1)82 {83 if (xrom.GenB.Count == 0)84 xrom.GenA[(N / 3) - 1]++;85 else86 xrom.GenB[xrom.GenB.Count - 1]++;87 xrom.ostB = 0;88 }89 else90 if (xrom.ostB == 0)91 buff = 0;92 else93 xrom.ostB -= buff = rand.Next(2, xrom.ostB);94 xrom.GenB.Add(buff);95 }96 xrom.GenB.Add(xrom.ostB);9798 ///99 for (int i = 0; i < N / 2 - 1; i++)100 {101 if (xrom.ostC == 2)102 {103 buff = 2;104 xrom.ostC = 0;105 }106 else107 if (xrom.ostC == 1)108 {109 xrom.GenC[xrom.GenC.Count - 1]++;110 xrom.ostC = 0;111 }112 else113 if (xrom.ostC == 0)114 buff = 0;115 else116 xrom.ostC -= buff = rand.Next(2, xrom.ostC);117 xrom.GenC.Add(buff);118 }119120 if (xrom.ostC == 1)121 {122 xrom.GenC[xrom.GenC.Count - 1]++;123 xrom.ostC = 0;124 }125 else126 xrom.GenC.Add(xrom.ostC);127128 return xrom;129 }130131 public List<Xromossomi> SetXrom()132 {133 for (int i = 0; i < 50; i++)134 {135 nabor.Add(nach());136 }137 xor();138139 return nabor;140 }141142 void xor()143 {144 int[] massA = new int[50];145 int[] massB = new int[50];146 int[] massC = new int[50];147 int buff;148 int v;149 for (int i = 0; i < 50; i++)150 {151 massA[i] = i;152 }153 List<Xromossomi> nabor1 = new List<Xromossomi>();154 for (int i = 0; i < 50; i++)155 nabor1.Add(new Xromossomi());156157 for (int i = 0; i < 50; i++)158 {159 buff = massA[v = rand.Next(50)];160 massA[v] = massA[v = rand.Next(50)];161 massA[v] = buff;162 }163 //164 for (int i = 0; i < 50; i++)165 {166 buff = massB[v = rand.Next(50)];167 massB[v] = massB[v = rand.Next(50)];168 massB[v] = buff;169 }170 //171 for (int i = 0; i < 50; i++)172 {173 buff = massC[v = rand.Next(50)];174 massC[v] = massC[v = rand.Next(50)];175 massC[v] = buff;176 }177178 for (int i = 0; i < 50; i++)179 {180 nabor1[i].GenA = nabor[massA[i]].GenA;181 nabor1[i].GenB = nabor[massA[i]].GenB;182 nabor1[i].GenC = nabor[massA[i]].GenC;183 }184 nabor = nabor1;185 }186 void mutation()187 {188 Random rand = new Random();189190 int i;191 foreach (var elem1 in nabor)192 {193194 for (int i1 = 0; i1 < 1; i1++)195 {196 if (elem1.GenA[i = rand.Next(elem1.GenA.Count - 1)] - 2 > 1)197 {198 elem1.GenA[i] -= 2;199 elem1.GenA[rand.Next(elem1.GenA.Count - 1)] += 2;200 }201 if (elem1.GenB[i = rand.Next(elem1.GenB.Count - 1)] - 2 > 1)202 {203 elem1.GenB[i] -= 2;204 elem1.GenB[rand.Next(elem1.GenB.Count - 1)] += 2;205 }206 if (elem1.GenC[i = rand.Next(elem1.GenC.Count - 1)] - 2 > 1)207 {208 elem1.GenC[i] -= 2;209 elem1.GenC[rand.Next(elem1.GenC.Count - 1)] += 2;210 }211 }212 };213 ...

Full Screen

Full Screen

GeNaProSpawnExtension.cs

Source:GeNaProSpawnExtension.cs Github

copy

Full Screen

1#if GENA_PRO2using GeNa.Core;3#endif4using System.Collections;5using System.Collections.Generic;6using UnityEngine;7namespace Gaia8{9 /// <summary>10 /// Simple Spawn Extension for demo / debug purposes. Just writes some info to the console when being executed.11 /// </summary>12 public class GeNaProSpawnExtension : MonoBehaviour, ISpawnExtension13 {14 public string Name { get { return "GeNaProSpawnExtension"; } }15 public bool AffectsHeights => false;16 public bool AffectsTextures => false;17 public GameObject m_genaSpawnerPrefab;18#if GENA_PRO19 private GeNa.Core.GeNaSpawner m_genaSpawnerInstance;20#endif21 public void Close()22 {23 ////Debug.Log("Spawn Extension is closing down.");24 //if (m_genaSpawnerInstance != null)25 //{26 // DestroyImmediate(m_genaSpawnerInstance.gameObject);27 //}28 }29 public void Init(Spawner spawner)30 {31#if GENA_PRO32 //Debug.Log("Spawn Extension starting up.");33 if (m_genaSpawnerPrefab == null)34 {35 Debug.LogWarning("GeNa Spawn Extension '" + Name + "' does not have a GeNa Spawner Prefab assigned.");36 return;37 }38 m_genaSpawnerInstance = m_genaSpawnerPrefab.GetComponent<GeNa.Core.GeNaSpawner>();39 if (m_genaSpawnerInstance == null)40 {41 Debug.LogWarning("Could not find a GeNa Spawner component on the prefab for GeNa Spawn Extension '" + Name + "'. Does this prefab use a GeNa Spawner component on the top level?");42 }43#endif44 }45 public void Spawn(Spawner spawner, Transform target, int ruleIndex, int instanceIndex, SpawnExtensionInfo spawnExtensionInfo)46 {47#if GENA_PRO48 //Debug.Log("Spawn Extension spawning.");49 if (m_genaSpawnerInstance != null)50 {51 m_genaSpawnerInstance.Load();52 GeNaSpawnerData data = m_genaSpawnerInstance.SpawnerData;53 SpawnCall spawnCall = GeNaSpawnerInternal.GenerateSpawnCall(data, spawnExtensionInfo.m_position);54 m_genaSpawnerInstance.Save();55 GeNaSpawnerInternal.SetSpawnOrigin(data, spawnCall, true);56 m_genaSpawnerInstance.Spawn(spawnExtensionInfo.m_position);57 m_genaSpawnerInstance.GetParent().SetParent(target);58 }59#endif60 }61 public void Delete(Transform target)62 {63 DestroyImmediate(target.gameObject);64 }65 }66}...

Full Screen

Full Screen

shared-generic-methods.2.cs

Source:shared-generic-methods.2.cs Github

copy

Full Screen

...4namespace GenericSharingTest {5public class ClassA {}6public class ClassB {}7public class ClassC {}8public class GenA<T> {9 public int genericMethod<M> () {10 return 123;11 }12 public int genericMethodCaller () {13 return genericMethod<int> ();14 }15}16public class main {17 static bool haveError = false;18 public static void error (string message) {19 haveError = true;20 Console.WriteLine (message);21 }22 public static void typeCheck (String method, Object obj, Type t) {23 if (obj.GetType () != t)24 error ("object from " + method + " should have type " + t.ToString () + " but has type " + obj.GetType ().ToString ());25 }26 public static int Main ()27 {28 GenA<ClassA> ga = new GenA<ClassA> ();29 GenA<GenA<ClassB>> gaab = new GenA<GenA<ClassB>> ();30 if (ga.genericMethodCaller () != 123)31 error ("ga.genericMethodCaller");32 if (gaab.genericMethodCaller () != 123)33 error ("gaab.genericMethodCaller");34 if (haveError)35 return 1;36 return 0;37 }38}39}...

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 {4 static void Main()5 {6 GenB<int> obj = new GenB<int>();7 obj.show(10);8 }9 }10}11using System;12{13 {14 static void Main()15 {16 GenA obj = new GenA();17 obj.show<int>(10);18 }19 public void show<T>(T a)20 {21 Console.WriteLine(a);22 }23 }24}25using System;26{27 {28 void show(T a);29 }30 {31 static void Main()32 {33 GenA obj = new GenA();34 obj.show(10);35 }36 public void show(int a)37 {38 Console.WriteLine(a);39 }40 }41}42using System;43{44 delegate void Gen<T>(T a);45 {46 static void Main()47 {48 GenA obj = new GenA();49 Gen<int> obj1 = new Gen<int>(obj.show);50 obj1(10);51 }52 public void show(int a)53 {54 Console.WriteLine(a);55 }56 }57}58using System;59{60 {61 static void Main()62 {63 GenA[] obj = new GenA[10];64 for (int i = 0; i < 10; i++)65 {66 obj[i] = new GenA();67 }68 }69 }70}71using System;72using System.Collections.Generic;73{74 {75 static void Main()

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 static void Main()4 {5 GenA<int> a = new GenA<int>();6 }7}8{9 {10 }11}12error CS0234: The type or namespace name 'GenA' does not exist in the namespace 'B' (are you missing an assembly reference?)13using B;

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 public static void Main()4 {5 GenA ga = new GenA();6 ga.Display();7 }8}9using B;10{11 public static void Main()12 {13 GenB gb = new GenB();14 gb.Display();15 }16}17using B;18{19 public static void Main()20 {21 GenC gc = new GenC();22 gc.Display();23 }24}

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 static void Main()4 {5 GenA<int> genA = new GenA<int>();6 genA.Print();7 }8}9using B;10{11 static void Main()12 {13 GenB<int> genB = new GenB<int>();14 genB.Print();15 }16}17using B;18{19 static void Main()20 {21 GenA<int> genA = new GenA<int>();22 genA.Print();23 }24}25using B;26{27 static void Main()28 {29 GenB<int> genB = new GenB<int>();30 genB.Print();31 }32}33using B;34{35 static void Main()36 {37 GenA<int> genA = new GenA<int>();38 genA.Print();39 }40}41using B;42{43 static void Main()44 {45 GenB<int> genB = new GenB<int>();46 genB.Print();47 }48}49using B;50{51 static void Main()52 {53 GenA<int> genA = new GenA<int>();54 genA.Print();55 }56}57using B;58{59 static void Main()60 {61 GenB<int> genB = new GenB<int>();62 genB.Print();63 }64}65using B;66{67 static void Main()68 {69 GenA<int> genA = new GenA<int>();70 genA.Print();71 }72}73using B;

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1namespace A {2 class GenA {3 public GenA() {4 Console.WriteLine("GenA()");5 }6 }7}8namespace B {9 class GenB {10 public GenB() {11 Console.WriteLine("GenB()");12 }13 }14 class Derived : A.GenA {15 public Derived() {16 Console.WriteLine("Derived()");17 }18 }19 class Test {20 static void Main() {21 Derived d = new Derived();22 }23 }24}25GenA()26GenB()

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 public static void Main()4 {5 GenA<int> g = new GenA<int>();6 g.Set(10);7 int i = g.Get();8 System.Console.WriteLine("Value: {0}", i);9 GenA<string> g1 = new GenA<string>();10 g1.Set("Hello");11 System.Console.WriteLine("Value: {0}", g1.Get());12 }13}14using B;15{16 public static void Main()17 {18 GenB<int> g = new GenB<int>();19 g.Set(10);20 int i = g.Get();21 System.Console.WriteLine("Value: {0}", i);22 GenB<string> g1 = new GenB<string>();23 g1.Set("Hello");24 System.Console.WriteLine("Value: {0}", g1.Get());25 }26}27using B;28{29 public static void Main()30 {31 GenC<int> g = new GenC<int>();32 g.Set(10);33 int i = g.Get();34 System.Console.WriteLine("Value: {0}", i);35 GenC<string> g1 = new GenC<string>();36 g1.Set("Hello");37 System.Console.WriteLine("Value: {0}", g1.Get());38 }39}40using B;41{42 public static void Main()43 {44 GenD<int> g = new GenD<int>();45 g.Set(10);46 int i = g.Get();47 System.Console.WriteLine("Value: {0}", i);48 GenD<string> g1 = new GenD<string>();49 g1.Set("Hello");50 System.Console.WriteLine("Value: {0}", g1.Get());51 }52}53using B;54{55 public static void Main()56 {57 GenE<int> g = new GenE<int>();58 g.Set(10);59 int i = g.Get();60 System.Console.WriteLine("Value: {0}", i);

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 public static void Main()4 {5 GenA<string> obj = new GenA<string>();6 obj.set("Hello");7 System.Console.WriteLine(obj.get());8 }9}

Full Screen

Full Screen

GenA

Using AI Code Generation

copy

Full Screen

1using B;2{3 static void Main()4 {5 GenA<int> obj = new GenA<int>();6 obj.Display(100);7 }8}9using System;10{11 {12 void Display(T arg);13 }14 {15 public void Display(T arg)16 {17 Console.WriteLine(arg);18 }19 }20}21using A;22{23 static void Main()24 {25 IGen<int> obj = new GenA<int>();26 obj.Display(100);27 }28}29using System;30{31 {32 void Display(T arg);33 }34 {35 void Display(T arg);36 }37 {38 public void Display(T arg)39 {40 Console.WriteLine(arg);41 }42 void IGen2<T>.Display(T arg)43 {44 Console.WriteLine(arg);45 }46 }47}48using A;49{50 static void Main()51 {52 IGen<int> obj = new GenA<int>();53 obj.Display(100);54 IGen2<int> obj2 = new GenA<int>();55 obj2.Display(200);56 }57}58using System;59{60 {61 void Display(T arg);62 }63 {64 void Display(T arg);65 }66 {67 public void Display(T arg)68 {69 Console.WriteLine(arg);70 }71 void IGen2<T>.Display(T arg)72 {73 Console.WriteLine(arg);74 }75 }76}

Full Screen

Full Screen

Nunit tutorial

Nunit is a well-known open-source unit testing framework for C#. This framework is easy to work with and user-friendly. LambdaTest’s NUnit Testing Tutorial provides a structured and detailed learning environment to help you leverage knowledge about the NUnit framework. The NUnit tutorial covers chapters from basics such as environment setup to annotations, assertions, Selenium WebDriver commands, and parallel execution using the NUnit framework.

Chapters

  1. NUnit Environment Setup - All the prerequisites and setup environments are provided to help you begin with NUnit testing.
  2. NUnit With Selenium - Learn how to use the NUnit framework with Selenium for automation testing and its installation.
  3. Selenium WebDriver Commands in NUnit - Leverage your knowledge about the top 28 Selenium WebDriver Commands in NUnit For Test Automation. It covers web browser commands, web element commands, and drop-down commands.
  4. NUnit Parameterized Unit Tests - Tests on varied combinations may lead to code duplication or redundancy. This chapter discusses how NUnit Parameterized Unit Tests and their methods can help avoid code duplication.
  5. NUnit Asserts - Learn about the usage of assertions in NUnit using Selenium
  6. NUnit Annotations - Learn how to use and execute NUnit annotations for Selenium Automation Testing
  7. Generating Test Reports In NUnit - Understand how to use extent reports and generate reports with NUnit and Selenium WebDriver. Also, look into how to capture screenshots in NUnit extent reports.
  8. Parallel Execution In NUnit - Parallel testing helps to reduce time consumption while executing a test. Deep dive into the concept of Specflow Parallel Execution in NUnit.

NUnit certification -

You can also check out the LambdaTest Certification to enhance your learning in Selenium Automation Testing using the NUnit framework.

YouTube

Watch this tutorial on the LambdaTest Channel to learn how to set up the NUnit framework, run tests and also execute parallel testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful