public static void Init(IokeObject obj) { Runtime runtime = obj.runtime; obj.Kind = "Mixins"; obj.SetCell("=", runtime.Base.body.Get("=")); obj.SetCell("==", runtime.Base.body.Get("==")); obj.SetCell("cell", runtime.Base.body.Get("cell")); obj.SetCell("cell=", runtime.Base.body.Get("cell=")); obj.SetCell("cell?", runtime.Base.body.Get("cell?")); obj.SetCell("cells", runtime.Base.body.Get("cells")); obj.SetCell("cellNames", runtime.Base.body.Get("cellNames")); obj.SetCell("mimic", runtime.Base.body.Get("mimic")); IokeObject comparing = new IokeObject(obj.runtime, "allows different objects to be compared, based on the spaceship operator being available"); comparing.MimicsWithoutCheck(obj); Comparing.Init(comparing); obj.RegisterCell("Comparing", comparing); IokeObject enumerable = new IokeObject(obj.runtime, "adds lots of helpful methods that can be done on enumerable methods. based on the 'each' method being available on the self."); enumerable.MimicsWithoutCheck(obj); Enumerable.Init(enumerable); obj.RegisterCell("Enumerable", enumerable); IokeObject sequenced = new IokeObject(obj.runtime, "something that is sequenced can return a Sequence over itself. it also allows several other methods to be defined in terms of that sequence. A Sequenced object is Enumerable, since all Enumerable operations can be defined in terms of sequencing."); sequenced.MimicsWithoutCheck(obj); sequenced.MimicsWithoutCheck(enumerable); Sequenced.Init(sequenced); obj.RegisterCell("Sequenced", sequenced); }
public override void PartOne() { var order = Comparing <Particle> .By(p => p.Acceleration.Magnitude()) .ThenBy(p => p.Velocity.Magnitude()) .ThenBy(p => p.Pos.Magnitude()); var result = ReadParticles().OrderBy(order).First().Num; WriteLn(result); }
public static void Sort(string[] strings, Comparing del) { if (strings == null || del == null) { return; } for (var i = 0; i < strings.Length - 1; i++)//todo pn давай не пузырьковой сортировкой, а более оптимальной { for (var j = i + 1; j < strings.Length; j++) { Compare(ref strings[i], ref strings[j]); } } }
/// <summary> /// Проводит тестирование метода int Compare(out string firstUnmatchedValue, out string secondUnmatchedValue). /// </summary> /// <param name="expectedValue">Ожидаемое возвращаемое значение.</param> /// <param name="firstFileName">Путь к первому проверяемому файлу.</param> /// <param name="secondFileName">Путь ко второму проверяемому файлу.</param> /// <param name="expectedFirstLine">Ожидаемое возвращаемое значение отличающейся строки результирующего файла.</param> /// <param name="expectedSecondLine">Ожидаемое возвращаемое значение отличающейся строки эталонного файла.</param> private void TestBody(int expectedValue, string firstFileName, string secondFileName, string expectedFirstLine, string expectedSecondLine) { //Arrange string testFilesFolder = Path.Combine(Environment.CurrentDirectory.Replace("\\bin\\Debug", ""), @"test files"); string firstTestFile = Path.Combine(testFilesFolder, firstFileName); string secondTestFile = Path.Combine(testFilesFolder, secondFileName); Comparing compare = new Comparing(); compare.ResultPath = firstTestFile; compare.ReferencePath = secondTestFile; //Act int actualValue = compare.Compare(out string actualFirstLine, out string actualSecondLine); //Assert Assert.AreEqual(expectedValue, actualValue, "Номер строки с отличием некорректен."); Assert.AreEqual(actualFirstLine, expectedFirstLine, "Значение несовпавшей строки результирующего файла некорректно."); Assert.AreEqual(actualSecondLine, expectedSecondLine, "Значение несовпавшей строки эталонного файла некорректно."); }
static void Main(string[] args) { double x, y; Console.WriteLine("Введите Х"); x = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Введите Y"); y = Convert.ToDouble(Console.ReadLine()); ComparingMethod(x, y, Bigger); ComparingMethod(x, y, Lower); //Лямбда-выражение Comparing biggerlambda = (double x, double y) => { if (x > y) { return($"{x} больше, чем {y}"); } else if (y > x) { return($"{y} больше, чем {x}"); } else { return($"{x} и {y} равны"); } }; ComparingMethod(x, y, biggerlambda); Console.WriteLine("Нажмите любую клавишу для продолжения"); Console.ReadLine(); //Обобщенные делегаты ComparingMethodFunc(x, y, Lower); Console.WriteLine("----------------------------------------------------------"); AssemblyInfo(); TypeInfo(); InvokeMemberInfo(); AttributeInfo(); }
public override void PartOne() { var graph = Input.ToDigraph(s => s[5], s => s[36]); var queue = new SelfPriorityQueue <Vertex <char, DirectedEdge <char> > >(Comparing <Vertex <char, DirectedEdge <char> > > .By(vertex => vertex.Value)); foreach (var vertex in graph.Where(vertex => !graph.HasIncomingEdges(vertex))) { queue.Enqueue(vertex); } while (queue.Count > 0) { var vertex = queue.Dequeue(); Write(vertex.Value); var next = vertex.Neighbors.ToList(); graph.RemoveVertex(vertex); foreach (var v in next.Where(v => !graph.HasIncomingEdges(v))) { queue.Enqueue(v); } } NewLine(); }
//Метод с делегатным параметром static void ComparingMethod(double x, double y, Comparing parameter) { string result = parameter(x, y); Console.WriteLine(result); }