public static string TestDeCateOriIntra() { object[,] teste = new object[, ] { { "0", "0", "0" }, { "1", "1", "1" }, { "1", "2", "2" }, { "1", "3", "3" }, { "2", "4", "2" }, { "6", "12", "2" }, { "24", "12", "0" }, { "113", "355", "3" }, { "456", "1368", "3" }, { "74916", "674244", "9" }, { "44", "1242", "28" }, { "51", "500", "9" } }; string str = ""; for (int i = 0; i < teste.GetLength(0); i++) { List <int> b = new List <int>(); for (int j = 0; j < ((string)teste[i, 0]).Length; j++) { b.Add(Floatz.charToInt(((string)teste[i, 0])[j])); } List <int> temp = new List <int>(); for (int j = 0; j < ((string)teste[i, 1]).Length; j++) { temp.Add(Floatz.charToInt(((string)teste[i, 1])[j])); } List <int> resultCorrect = new List <int>(); for (int j = 0; j < ((string)teste[i, 2]).Length; j++) { resultCorrect.Add(Floatz.charToInt(((string)teste[i, 2])[j])); } List <int> result = Floatz.DeCateOriIntra(b, temp); if (Floatz.Compare2Lists(result, resultCorrect) != 0) { str += String.Format( "\n Test failed:DeCateOriIntra #{0} nereusita.\n \n b={1},temp={2}, result={3} |corect e: {4}\n\n", i, Floatz.ListToString(b), Floatz.ListToString(temp), Floatz.ListToString(result), Floatz.ListToString(resultCorrect) ); } } if (str == "") { return("Nu exista probleme la DeCateOriIntra."); } return(str); }
public static void PrintList(List <int> a, string prefix = "") { Console.WriteLine(prefix + Floatz.ListToString(a)); }
public static Floatz DivideFloatzWithList(Floatz a, List <int> b, long nrMaxZecimalaLaImpartire, bool debugMode = false) { Floatz c = new Floatz(); List <int> temp = new List <int>(); int cmp = 0; for (int i = 0; i < a.intreaga.Count; i++) { temp.Add(a.intreaga[i]); cmp = Compare2Lists(temp, b); if (cmp < 1)//317/51 || 317 || 51 { List <int> deCateOriIntra = DeCateOriIntra(b, temp); List <int> sub = Floatz.Multiply2Lists(deCateOriIntra, b); if (debugMode) { Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra)); } c.intreaga.AddRange(deCateOriIntra); if (debugMode) { Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "="); } temp = Floatz.Subtract2Lists(temp, sub); if (debugMode) { Console.Write(Floatz.ListToString(temp)); Console.WriteLine(); } if (Floatz.ListIsZero(temp)) { break; } } else { c.intreaga.Add(0); } } c.ComprimaIntreaga(); if (nrMaxZecimalaLaImpartire == 0) { return(c); } c.zecimala.Clear(); if (Floatz.ListIsZero(temp)) { temp.Clear(); } if (debugMode) { Console.WriteLine(","); } for (int i = 0; i < a.zecimala.Count && nrMaxZecimalaLaImpartire >= 0; i++) { temp.Add(a.zecimala[i]); cmp = Compare2Lists(temp, b); if (cmp < 1) { List <int> deCateOriIntra = DeCateOriIntra(b, temp); List <int> sub = Floatz.Multiply2Lists(deCateOriIntra, b); if (debugMode) { Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra)); } c.zecimala.AddRange(deCateOriIntra.GetRange(0, Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire))); nrMaxZecimalaLaImpartire -= Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire); if (debugMode) { Console.WriteLine("nrMaxZecimalaLaImpartire:" + nrMaxZecimalaLaImpartire); Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "="); } temp = Floatz.Subtract2Lists(temp, sub); cmp = Compare2Lists(temp, b); if (cmp == 1) { temp.Add(0); } if (debugMode) { Console.Write(Floatz.ListToString(temp)); Console.WriteLine(); } } else { c.zecimala.Add(0); nrMaxZecimalaLaImpartire--; } } if (!Floatz.ListIsZero(temp)) { if (debugMode) { Console.WriteLine("---start restu---"); } if (nrMaxZecimalaLaImpartire > 0) { if (cmp == 1) { temp.Add(0); } while (nrMaxZecimalaLaImpartire >= 0)//for (long i = nrMaxZecimalaLaImpartire; i >= 0; i--) { if (debugMode) { Console.WriteLine(Floatz.ListToString(temp)); } cmp = Compare2Lists(temp, b); if (debugMode) { Console.WriteLine(Floatz.ListToString(temp) + "?" + Floatz.ListToString(b) + "=" + cmp); } if (cmp < 1) { List <int> deCateOriIntra = DeCateOriIntra(b, temp); List <int> sub = Floatz.Multiply2Lists(deCateOriIntra, b); if (debugMode) { Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra)); } c.zecimala.AddRange(deCateOriIntra.GetRange(0, Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire))); nrMaxZecimalaLaImpartire -= Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire); if (nrMaxZecimalaLaImpartire == 0) { break; } if (debugMode) { Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "="); } temp = Floatz.Subtract2Lists(temp, sub); cmp = Compare2Lists(temp, b); if (cmp == 1) { temp.Add(0); } if (debugMode) { Console.Write(Floatz.ListToString(temp)); Console.WriteLine(); } if (Floatz.ListIsZero(temp)) { break; } } else { if (debugMode) { Console.WriteLine("0 was added."); } c.zecimala.Add(0); temp.Add(0); nrMaxZecimalaLaImpartire--; } } } } if (debugMode) { Console.WriteLine("."); } c.ComprimaZecimala(); return(c); }