How to use GenB class of B package

Best Nunit code snippet using B.GenB

generics-sharing.2.cs

Source:generics-sharing.2.cs Github

copy

Full Screen

...12 public static void doThrow () {13 throw new GenExc<ClassA> ();14 }15}16public class GenBi<S,T> {17 public static int field = 123;18 public static float floatField = 1.0f;19 public static int staticMethod (int x) {20 return x + field;21 }22 public static void staticVoidMethod (int x) {23 field = x;24 }25 public static float staticFloatMethod () {26 return floatField;27 }28 public static long staticLongMethod (long x) {29 return x + field;30 }31 public static GenStruct<T> staticValueMethod (int x) {32 return new GenStruct<T> (x);33 }34}35public struct GenStruct<T> {36 public static int staticField;37 public int field;38 public int dummy1;39 public int dummy2;40 public int dummy3;41 public GenStruct (int f) {42 field = f;43 dummy1 = dummy2 = dummy3 = 0;44 }45 public int method (int x) {46 return x + field;47 }48}49public interface IGen<T> {50 T[] iMethod ();51 void voidIMethod (int x);52 long longIMethod (long x);53 float floatIMethod ();54 GenStruct<T> valueIMethod (int x);55}56public class IGenImpl<T> : IGen<T> {57 public int field;58 public T[] iMethod () {59 return new T[3];60 }61 public void voidIMethod (int x) {62 field = x;63 }64 public long longIMethod (long x) {65 return x + 1;66 }67 public float floatIMethod () {68 return 1.0f;69 }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);...

Full Screen

Full Screen

Gaa.cs

Source:Gaa.cs Github

copy

Full Screen

...16 int N = 10;17 static int size = 10;18 public List<int> GenA = new List<int>();19 public List<int> GenC = new List<int>();20 public List<int> GenB = new List<int>();21 public int ostA = size;22 public int ostB = size;23 public int ostC = size;24 public Xromossomi(int i)25 {26 ostA = i;27 ostB = i;28 ostC = i;29 }30 public Xromossomi() { }31 }32 Xromossomi nach()33 {34 Xromossomi xrom = new Xromossomi();35 int buff = 0;36 for (int i = 0; i < N / 2 - 1; i++)37 {38 if (xrom.ostA == 2)39 {40 buff = 2;41 xrom.ostA = 0;42 }43 else44 if (xrom.ostA == 1)45 {46 xrom.GenA[xrom.GenA.Count - 1]++;47 xrom.ostA = 0;48 buff = 0;49 }50 else51 if (xrom.ostA == 0)52 buff = 0;53 else54 xrom.ostA -= buff = rand.Next(2, xrom.ostA);55 xrom.GenA.Add(buff);56 }57 xrom.GenA.Add(xrom.ostA);58 //59 int s = N % 3 == 2 ? N / 3 + 1 : N / 3;60 int t = N % 3 == 1 || N % 3 == 2 ? N / 3 + 1 : N / 3;61 buff = 0;62 for (int i = 0; i < N / 2 - 1; i++)63 {64 if (xrom.ostB == 0 && 10 == xrom.GenA.Sum() && xrom.GenA[2] != 0)65 {66 }67 if (xrom.ostB == 2)68 {69 buff = 2;70 xrom.ostB = 0;71 }72 else73 if (xrom.ostB == 1)74 {75 if (xrom.GenB.Count == 0)76 xrom.GenA[(N / 3) - 1]++;77 else78 xrom.GenB[xrom.GenB.Count - 1]++;79 xrom.ostB = 0;80 }81 else82 if (xrom.ostB == 0)83 buff = 0;84 else85 xrom.ostB -= buff = rand.Next(2, xrom.ostB);86 xrom.GenB.Add(buff);87 }88 xrom.GenB.Add(xrom.ostB);89 ///90 for (int i = 0; i < N / 2 - 1; i++)91 {92 if (xrom.ostC == 2)93 {94 buff = 2;95 xrom.ostC = 0;96 }97 else98 if (xrom.ostC == 1)99 {100 xrom.GenC[xrom.GenC.Count - 1]++;101 xrom.ostC = 0;102 }103 else104 if (xrom.ostC == 0)105 buff = 0;106 else107 xrom.ostC -= buff = rand.Next(2, xrom.ostC);108 xrom.GenC.Add(buff);109 }110 if (xrom.ostC == 1)111 {112 xrom.GenC[xrom.GenC.Count - 1]++;113 xrom.ostC = 0;114 }115 else116 xrom.GenC.Add(xrom.ostC);117 return xrom;118 }119 public List<Xromossomi> SetXrom()120 {121 for (int i = 0; i < 50; i++)122 {123 nabor.Add(nach());124 }125 xor();126 return nabor;127 }128 void xor()129 {130 int[] massA = new int[50];131 int[] massB = new int[50];132 int[] massC = new int[50];133 int buff;134 int v;135 for (int i = 0; i < 50; i++)136 {137 massA[i] = i;138 }139 List<Xromossomi> nabor1 = new List<Xromossomi>();140 for (int i = 0; i < 50; i++)141 nabor1.Add(new Xromossomi());142 for (int i = 0; i < 50; i++)143 {144 buff = massA[v = rand.Next(50)];145 massA[v] = massA[v = rand.Next(50)];146 massA[v] = buff;147 }148 //149 for (int i = 0; i < 50; i++)150 {151 buff = massB[v = rand.Next(50)];152 massB[v] = massB[v = rand.Next(50)];153 massB[v] = buff;154 }155 //156 for (int i = 0; i < 50; i++)157 {158 buff = massC[v = rand.Next(50)];159 massC[v] = massC[v = rand.Next(50)];160 massC[v] = buff;161 }162 for (int i = 0; i < 50; i++)163 {164 nabor1[i].GenA = nabor[massA[i]].GenA;165 nabor1[i].GenB = nabor[massA[i]].GenB;166 nabor1[i].GenC = nabor[massA[i]].GenC;167 }168 nabor = nabor1;169 }170 void mutation()171 {172 Random rand = new Random();173 int i;174 foreach (var elem1 in nabor)175 {176 for (int i1 = 0; i1 < 1; i1++)177 {178 if (elem1.GenA[i = rand.Next(elem1.GenA.Count - 1)] - 2 > 1)179 {180 elem1.GenA[i] -= 2;181 elem1.GenA[rand.Next(elem1.GenA.Count - 1)] += 2;182 }183 if (elem1.GenB[i = rand.Next(elem1.GenB.Count - 1)] - 2 > 1)184 {185 elem1.GenB[i] -= 2;186 elem1.GenB[rand.Next(elem1.GenB.Count - 1)] += 2;187 }188 if (elem1.GenC[i = rand.Next(elem1.GenC.Count - 1)] - 2 > 1)189 {190 elem1.GenC[i] -= 2;191 elem1.GenC[rand.Next(elem1.GenC.Count - 1)] += 2;192 }193 }194 };195 }196 }197}...

Full Screen

Full Screen

AdventDay15UnitTests.cs

Source:AdventDay15UnitTests.cs Github

copy

Full Screen

1using Microsoft.VisualStudio.TestTools.UnitTesting;2using AdventCodeLib;3namespace AdventCode4{5 [TestClass]6 [Ignore]7 public class AdventDay15UnitTests8 {9 Generator genA;10 Generator genB;11 long factorA = 16807;12 long factorB = 48271;13 [TestInitialize]14 public void TestSetup()15 {16 genA = new Generator(65, factorA);17 genB = new Generator(8921, factorB);18 }19 [TestMethod]20 public void Day15_TestRun01()21 {22 // --Gen.A-- --Gen.B--23 // 1092455 43062559124 Assert.AreEqual(1092455, genA.Generate());25 Assert.AreEqual(430625591, genB.Generate());26 Assert.IsFalse(Generator.Match(genA, genB));27 // 1181022009 123368384828 Assert.AreEqual(1181022009, genA.Generate());29 Assert.AreEqual(1233683848, genB.Generate());30 Assert.IsFalse(Generator.Match(genA, genB));31 // 245556042 143149549832 Assert.AreEqual(245556042, genA.Generate());33 Assert.AreEqual(1431495498, genB.Generate());34 Assert.IsTrue(Generator.Match(genA, genB));35 // 1744312007 13787443936 Assert.AreEqual(1744312007, genA.Generate());37 Assert.AreEqual(137874439, genB.Generate());38 Assert.IsFalse(Generator.Match(genA, genB));39 // 1352636452 28522291640 Assert.AreEqual(1352636452, genA.Generate());41 Assert.AreEqual(285222916, genB.Generate());42 Assert.IsFalse(Generator.Match(genA, genB));43 }44 [TestMethod]45 public void Day15_TestRun02()46 {47 long expected = 588;48 long actual = 0;49 int length = 40000000;50 for (int i = 0; i < length; i++)51 {52 genA.Generate();53 genB.Generate();54 if (Generator.Match(genA, genB))55 {56 actual++;57 }58 }59 Assert.AreEqual(expected, actual);60 }61 [TestMethod]62 public void Day15_TestRun03()63 {64 genA.Check = 4;65 genB.Check = 8;66 // --Gen.A----Gen.B--67 // 1352636452 123368384868 Assert.AreEqual(1352636452, genA.Generate2());69 Assert.AreEqual(1233683848, genB.Generate2());70 Assert.IsFalse(Generator.Match(genA, genB));71 // 1992081072 86251635272 Assert.AreEqual(1992081072, genA.Generate2());73 Assert.AreEqual(862516352, genB.Generate2());74 Assert.IsFalse(Generator.Match(genA, genB));75 // 530830436 115978456876 Assert.AreEqual(530830436, genA.Generate2());77 Assert.AreEqual(1159784568, genB.Generate2());78 Assert.IsFalse(Generator.Match(genA, genB));79 // 1980017072 161605767280 Assert.AreEqual(1980017072, genA.Generate2());81 Assert.AreEqual(1616057672, genB.Generate2());82 Assert.IsFalse(Generator.Match(genA, genB));83 // 740335192 41226939284 Assert.AreEqual(740335192, genA.Generate2());85 Assert.AreEqual(412269392, genB.Generate2());86 Assert.IsFalse(Generator.Match(genA, genB));87 }88 [TestMethod]89 public void Day15_TestRun04()90 {91 genA.Check = 4;92 genB.Check = 8;93 for (int i = 0; i < 1056; i++)94 {95 genA.Generate2();96 genB.Generate2();97 }98 Assert.IsTrue(Generator.Match(genA, genB));99 }100 [TestMethod]101 public void Day15_TestRun05()102 {103 long expected = 309;104 long actual = 0;105 int length = 5000000;106 genA.Check = 4;107 genB.Check = 8;108 for (int i = 0; i < length; i++)109 {110 genA.Generate2();111 genB.Generate2();112 if (Generator.Match(genA, genB))113 {114 actual++;115 }116 }117 Assert.AreEqual(expected, actual);118 }119 [TestMethod]120 public void Day15_TestSolutionA()121 {122 genA = new Generator(703, factorA);123 genB = new Generator(516, factorB);124 long expected = 594;125 long actual = 0;126 int length = 40000000;127 for (int i = 0; i < length; i++)128 {129 genA.Generate();130 genB.Generate();131 if (Generator.Match(genA, genB))132 {133 actual++;134 }135 }136 Assert.AreEqual(expected, actual);137 }138 [TestMethod]139 public void Day15_TestSolutionB()140 {141 genA = new Generator(703, factorA);142 genB = new Generator(516, factorB);143 long expected = 328;144 long actual = 0;145 int length = 5000000;146 genA.Check = 4;147 genB.Check = 8;148 for (int i = 0; i < length; i++)149 {150 genA.Generate2();151 genB.Generate2();152 if (Generator.Match(genA, genB))153 {154 actual++;155 }156 }157 Assert.AreEqual(expected, actual);158 }159 }160}...

Full Screen

Full Screen

Day15.cs

Source:Day15.cs Github

copy

Full Screen

1using System;2namespace AdventOfCode.Year20173{4 public class Day15 : IAoC5 {6 public string SolvePart1(string input)7 {8 int matches = 0;9 //Convert.ToString(val, 2).PadLeft(4, '0')10 var generatorsStart = Array.ConvertAll(input.Split(' ', StringSplitOptions.RemoveEmptyEntries), long.Parse);11 long genA = generatorsStart[0], genB = generatorsStart[1];12 for (int i = 0; i < 40000000; i++)13 {14 genA = (genA * 16807) % 2147483647;15 genB = (genB * 48271) % 2147483647;16 var a1 = Convert.ToString(genA, 2).PadLeft(32, '0');17 var b1 = Convert.ToString(genB, 2).PadLeft(32, '0');18 if (a1.Substring(16) == b1.Substring(16))19 {20 matches++;21 }22 }23 return matches.ToString();24 }25 public string SolvePart2(string input)26 {27 int matches = 0;28 //Convert.ToString(val, 2).PadLeft(4, '0')29 var generatorsStart = Array.ConvertAll(input.Split(' ', StringSplitOptions.RemoveEmptyEntries), long.Parse);30 long genA = generatorsStart[0], genB = generatorsStart[1];31 for (int i = 0; i < 5000000; i++)32 {33 genA = (genA * 16807) % 2147483647;34 while (genA % 4 != 0) { genA = (genA * 16807) % 2147483647; }35 genB = (genB * 48271) % 2147483647;36 while (genB % 8 != 0) { genB = (genB * 48271) % 2147483647; ; }37 var a1 = Convert.ToString(genA, 2).PadLeft(32, '0');38 var b1 = Convert.ToString(genB, 2).PadLeft(32, '0');39 if (a1.Substring(16) == b1.Substring(16))40 {41 matches++;42 }43 }44 return matches.ToString();45 }46 public string GetInput() => "289 629";47 }48}...

Full Screen

Full Screen

15.cs

Source:15.cs Github

copy

Full Screen

...4{5 public class Challenge15 : Challenge6 {7 private const long GenAFactor = 16807;8 private const long GenBFactor = 48271;9 private const long ModFactor = 2147483647;10 /* there is undoubtedly a smarter way to handle this than actually11 iterating 40M times. This runs in ~750ms for pt1 and ~1400 for pt2,12 so it isn't *terrible* considering the sheer number of calcs.13 I'll try to get back to this later.14 */15 public override object Task1()16 {17 long GenA = int.Parse(input[0].Split(' ')[^1]);18 long GenB = int.Parse(input[1].Split(' ')[^1]);19 int total = 0;20 for (int i = 1; i < 40_000_000; i++)21 {22 GenA = (GenA * GenAFactor) % ModFactor;23 GenB = (GenB * GenBFactor) % ModFactor;24 if ((GenA & ushort.MaxValue) == (GenB & ushort.MaxValue)) total++;25 }26 return total;27 }28 public override object Task2()29 {30 long GenA = int.Parse(input[0].Split(' ')[^1]);31 long GenB = int.Parse(input[1].Split(' ')[^1]);32 Queue<long> AQueue = new Queue<long>();33 while (AQueue.Count < 5_000_000)34 {35 GenA = (GenA * GenAFactor) % ModFactor;36 if (GenA % 4 == 0) AQueue.Enqueue(GenA & ushort.MaxValue);37 }38 int total = 0;39 for (int i = 0; i < 5_000_000;)40 {41 GenB = (GenB * GenBFactor) % ModFactor;42 if (GenB % 8 == 0)43 {44 i++;45 if (AQueue.Dequeue() == (GenB & ushort.MaxValue)) total++;46 }47 }48 return total;49 }50 }51}...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

1using System;2namespace day153{4 class Program5 {6 static void Main(string[] args)7 {8 ulong genA = 116; //65;9 ulong genB = 299; //8921;10 var res1 = Task1(genA, genB);11 Console.WriteLine(res1);12 var res2 = Task2(genA, genB);13 Console.WriteLine(res2);14 Console.ReadLine();15 }16 private static int Task1(ulong genA, ulong genB)17 {18 int judge = 0;19 for (int i = 0; i < 40000000; i++)20 {21 genA = (genA * 16807) % 2147483647;22 genB = (genB * 48271) % 2147483647;23 if ((genA & 0xffff) == (genB & 0xffff))24 {25 judge++;26 }27 }28 return judge;29 }30 private static int Task2(ulong genA, ulong genB)31 {32 int judge = 0;33 for (int i = 0; i < 5000000; i++)34 {35 do36 {37 genA = (genA * 16807) % 2147483647;38 } while (genA % 4 != 0);39 do40 {41 genB = (genB * 48271) % 2147483647;42 } while (genB % 8 != 0);43 if ((genA & 0xffff) == (genB & 0xffff))44 {45 judge++;46 }47 }48 return judge;49 }50 }51}...

Full Screen

Full Screen

recursive-generics.2.cs

Source:recursive-generics.2.cs Github

copy

Full Screen

1using System;2public class GenA<T> {};3public class GenB<T> : GenA<GenB<GenB<T>>> {};4public class GenC<T> {5 public object newA () {6 return new GenA<T> ();7 }8}9public class GenD<T> : GenC<GenD<GenD<T>>> {};10public class main {11 public static int Main () {12 GenB<string> gb = new GenB<string> ();13 GenD<string> gd = new GenD<string> ();14 gd.newA ();15 return 0;16 }17}...

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 GenB<int> b = new GenB<int>();4}5using C;6{7 GenC<int> c = new GenC<int>();8}9using C;10{11 GenC<int> c = new GenC<int>();12}13using B;14{15 GenB<int> b = new GenB<int>();16}17using C;18{19 GenC<int> c = new GenC<int>();20}21using C;22{23 GenC<int> c = new GenC<int>();24}25using B;26{27 GenB<int> b = new GenB<int>();28}29using C;30{31 GenC<int> c = new GenC<int>();32}33using C;34{35 GenC<int> c = new GenC<int>();36}37using B;38{39 GenB<int> b = new GenB<int>();40}41using C;42{43 GenC<int> c = new GenC<int>();44}45using C;46{47 GenC<int> c = new GenC<int>();48}49using B;50{

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 {4 public void MethodA(T t)5 {6 GenB<T> genB = new GenB<T>();7 genB.MethodB(t);8 }9 }10}11using A;12{13 {14 public void MethodC()15 {16 GenA<int> genA = new GenA<int>();17 genA.MethodA(10);18 }19 }20}

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3public static void Main()4{5GenB b = new GenB();6b.Show();7}8}9using A;10{11public static void Main()12{13GenA a = new GenA();14a.Show();15}16}17{18{19public void Show()20{21System.Console.WriteLine("B");22}23}24}25{26{27public void Show()28{29System.Console.WriteLine("A");30}31}32}

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 static void Main()4 {5 GenB b = new GenB();6 b.Display();7 }8}9using A;10{11 static void Main()12 {13 GenA a = new GenA();14 a.Display();15 }16}

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 public static void Main()4 {5 GenB<int> b = new GenB<int>();6 b.Show();7 }8}

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 public static void Main()4 {5 GenB<int> obj = new GenB<int>();6 }7}8using A;9{10 public static void Main()11 {12 GenA<int> obj = new GenA<int>();13 }14}15using B;16{17 public static void Main()18 {19 GenB<int> obj = new GenB<int>();20 }21}

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2{3 static void Main()4 {5 GenB<int> gb = new GenB<int>();6 gb.Show();7 }8}9In Show() of B.GenB10In Show() of A.GenA11using B;12{13 static void Main()14 {15 B.GenB<int> gb = new B.GenB<int>();16 gb.Show();17 }18}19In Show() of B.GenB20In Show() of A.GenA21using B1 = B;22{23 static void Main()24 {25 B1.GenB<int> gb = new B1.GenB<int>();26 gb.Show();27 }28}29In Show() of B.GenB30In Show() of A.GenA31In the above example, we have used the alias B1 for the namespace B. So, the compiler will search for the class GenB in the namespace B. If the class is found, then the compiler will call the Show() method of GenB class. If the class is not found, then the compiler will throw an

Full Screen

Full Screen

GenB

Using AI Code Generation

copy

Full Screen

1using B;2class GenBUser {3 public static void Main() {4 GenB<int> b = new GenB<int>();5 b.Show();6 }7}

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