public void Append_entries_to_a_list_and_return_the_new_list_non_empty_lists() { var list1 = new List <int> { 1, 2 }; var list2 = new List <int> { 2, 3, 4, 5 }; var expected = new List <int> { 1, 2, 2, 3, 4, 5 }; Assert.Equal(expected, ListOps.Append(list1, list2)); }
public Node TryEval(Node node, Env env, Logger logger) { Node currentListNode = node.Tail; Node list = null; while (currentListNode != Node.NIL) { Node newEntry = Evaluator.Evaluate(currentListNode.Head, env); list = ListOps.AppendToList(newEntry, list); currentListNode = currentListNode.Tail; } return(list); }
private static Dictionary <string, Node> CreateReplacements(Node parameters, Node node) { // Create replacements Dictionary <string, Node> replaceMap = new Dictionary <string, Node>(); Node currentParameterNode = parameters; Node currentValueNode = node.Tail; while (currentParameterNode != Node.NIL) { string key = currentParameterNode.Head.Content.ToString(); if ("&rest".Equals(key)) { string restParameterName = currentParameterNode.Tail.Head.Content.ToString(); Node restParameterValues = null; while (currentValueNode != Node.NIL) { restParameterValues = ListOps.AppendToList(currentValueNode.Head, restParameterValues); currentValueNode = currentValueNode.Tail; } replaceMap[restParameterName] = restParameterValues; return(replaceMap); } Node value = currentValueNode.Head; replaceMap[key] = value; currentParameterNode = currentParameterNode.Tail; currentValueNode = currentValueNode.Tail; } int remainingLength = ListOps.CalculateListLength(currentValueNode); if (remainingLength > 0) { throw new ArgumentException("MacroExpander.CreateReplacements: " + remainingLength + " additional parameters found."); } return(replaceMap); }
public void ConcatOfListOfLists() { Assert.Equal(Range(1, 6), ListOps.Concat(new List <List <int> > { new List <int> { 1, 2 }, new List <int> { 3 }, EmptyList, new List <int> { 4, 5, 6 } })); }
public void Concatenate_a_list_of_lists_list_of_lists() { var lists = new List <List <int> > { new List <int> { 1, 2 }, new List <int> { 3 }, new List <int>(), new List <int> { 4, 5, 6 } }; var expected = new List <int> { 1, 2, 3, 4, 5, 6 }; Assert.Equal(expected, ListOps.Concat(lists)); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IComparer<string> Members public int Compare( string left, string right ) { ListOps.GetElementsToCompare( interpreter, ascending, indexText, leftOnly, false, cultureInfo, ref left, ref right); /* throw */ int result = String.Compare(left, right, noCase ? StringOps.SystemNoCaseStringComparisonType : StringOps.SystemStringComparisonType); ListOps.UpdateDuplicateCount(this, duplicates, left, right, unique, result, ref levels); /* throw */ return(result); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IComparer<string> Members public int Compare( string left, string right ) { Result error = null; ListOps.GetElementsToCompare( interpreter, ascending, indexText, leftOnly, false, cultureInfo, ref left, ref right); /* throw */ Number leftNumber = null; if ((Value.GetNumber(left, ValueFlags.AnyNumberAnyRadix, cultureInfo, ref leftNumber, ref error) == ReturnCode.Ok) && leftNumber.ConvertTo(typeof(double))) { double leftDouble = (double)leftNumber.Value; Number rightNumber = null; if ((Value.GetNumber(right, ValueFlags.AnyNumberAnyRadix, cultureInfo, ref rightNumber, ref error) == ReturnCode.Ok) && rightNumber.ConvertTo(typeof(double))) { double rightDouble = (double)rightNumber.Value; int result = LogicOps.Compare(leftDouble, rightDouble); ListOps.UpdateDuplicateCount(this, duplicates, leftDouble.ToString(), rightDouble.ToString(), unique, result, ref levels); /* throw */ return(result); } } if (error != null) { throw new ScriptException(error); } else { throw new ScriptException(); } }
public Node TryEval(Node node, Env env, Logger logger) { // Append values (second to n-th parameter) to a list (first parameter). Node list = Evaluator.Evaluate(node.Tail.Head, env); Node listOfValues = node.Tail.Tail; while (listOfValues != Node.NIL) { Node n = listOfValues.Head; Node result = Evaluator.Evaluate(n, env); list = ListOps.AppendToList(list, result); listOfValues = listOfValues.Tail; } return(list); }
public Node TryEval(Node node, Env env, Logger logger) { double result = 0.0; int nodeChildrenCount = ListOps.CalculateListLength(node); if (nodeChildrenCount > 1) { Node parameter0 = Evaluator.Evaluate(NodeOps.GetChild(node, 1), env); result = double.Parse(parameter0.Content.ToString(), CultureInfo.InvariantCulture); for (int i = 2; i < nodeChildrenCount; i++) { Node parameter = Evaluator.Evaluate(NodeOps.GetChild(node, i), env); result -= double.Parse(parameter.Content.ToString(), CultureInfo.InvariantCulture); } } string resultStr = result.ToString(CultureInfo.InvariantCulture); return(new Node(StdNodeTypes.Identifier, resultStr)); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IComparer<string> Members public int Compare( string left, string right ) { Result error = null; ListOps.GetElementsToCompare( interpreter, ascending, indexText, leftOnly, false, cultureInfo, ref left, ref right); /* throw */ long leftWide = 0; if (Value.GetWideInteger2(left, ValueFlags.AnyWideInteger, cultureInfo, ref leftWide, ref error) == ReturnCode.Ok) { long rightWide = 0; if (Value.GetWideInteger2(right, ValueFlags.AnyWideInteger, cultureInfo, ref rightWide, ref error) == ReturnCode.Ok) { int result = LogicOps.Compare(leftWide, rightWide); ListOps.UpdateDuplicateCount(this, duplicates, leftWide.ToString(), rightWide.ToString(), unique, result, ref levels); /* throw */ return(result); } } if (error != null) { throw new ScriptException(error); } else { throw new ScriptException(); } }
public void Reverse_the_elements_of_the_list_list_of_lists_is_not_flattened() { var list = new List <List <int> > { new List <int> { 1, 2 }, new List <int> { 3 }, new List <int>(), new List <int> { 4, 5, 6 } }; var expected = new List <List <int> > { new List <int> { 4, 5, 6 }, new List <int>(), new List <int> { 3 }, new List <int> { 1, 2 } }; Assert.Equal(expected, ListOps.Reverse(list)); }
public void Returns_the_length_of_a_list_empty_list() { var list = new List <int>(); Assert.Equal(0, ListOps.Length(list)); }
public void FoldlOfHugeList() { Assert.Equal(Big * (Big + 1L) / 2L, ListOps.Foldl((acc, x) => acc + x, 0L, Range(1, Big))); }
public void AppendOfNonEmptyAndEmptyLists() { Assert.Equal(Range(1, 4), ListOps.Append(Range(1, 4), EmptyList)); }
public void FoldlOfEmptylist() { Assert.Equal(0, ListOps.Foldl((acc, x) => acc + x, 0, EmptyList)); }
public void FoldlOfNonEmptyList() { Assert.Equal(7, ListOps.Foldl((acc, x) => acc + x, -3, Range(1, 4))); }
public void AppendOfLargeLists() { Assert.Equal(BigList, ListOps.Append(Range(1, Big / 2), Range(1 + Big / 2, Big))); }
public void FilterOfNormalList() { Assert.Equal(new List <int> { 1, 3 }, ListOps.Filter(Odd, Range(1, 4))); }
public void ReverseOfNonEmptyList() { Assert.Equal(Range(1, 100).OrderByDescending(x => x).ToList(), ListOps.Reverse(Range(1, 100))); }
public void MapOfEmptylist() { Assert.Equal(EmptyList, ListOps.Map(x => x + 1, EmptyList)); }
public void LengthOfLargeList() { Assert.Equal(Big, ListOps.Length(Range(1, Big))); }
public void ReverseOfEmptylist() { Assert.Equal(EmptyList, ListOps.Reverse(EmptyList)); }
public void AppendOfNonEmptylists() { Assert.Equal(Range(1, 5), ListOps.Append(Range(1, 3), new List <int> { 4, 5 })); }
public void Concatenate_a_list_of_lists_empty_list() { var lists = new List <List <int> >(); Assert.Empty(ListOps.Concat(lists)); }
public void ConcatOfLargeListOfSmallLists() { Assert.Equal(BigList, ListOps.Concat(ListOps.Map(x => new List <int> { x }, Range(1, Big)))); }
public void Reverse_the_elements_of_the_list_empty_list() { var list = new List <int>(); Assert.Empty(ListOps.Reverse(list)); }
public void FilterOfEmptylist() { Assert.Equal(EmptyList, ListOps.Filter(x => true, EmptyList)); }
public void LengthOfEmptyList() { Assert.Equal(0, ListOps.Length(EmptyList)); }
public void ConcatOfNoLists() { Assert.Equal(EmptyList, ListOps.Concat(new List <List <int> >())); }
public void LengthOfNonEmptyList() { Assert.Equal(4, ListOps.Length(Range(1, 4))); }
public ManagedObject (object obj) { // Console.WriteLine ("new ManagedObject created wrapping object of type {0}, handle == {1}", obj.GetType(), Handle); managed = obj; Type type = obj.GetType (); bool isScriptable = type.IsDefined (typeof(ScriptableTypeAttribute), true); // add properties foreach (PropertyInfo pi in type.GetProperties ()) { if (!isScriptable && !pi.IsDefined (typeof(ScriptableMemberAttribute), true)) continue; RegisterScriptableProperty (pi); if (RegisterScriptableTypes (pi)) HasTypes = true; } // add events foreach (EventInfo ei in type.GetEvents ()) { if (!isScriptable && !ei.IsDefined (typeof(ScriptableMemberAttribute), true)) continue; RegisterScriptableEvent (ei); HasEvents = true; // XXX toshok - do we need to RegisterScriptableTypes for parameters on the delegate? } // add functions foreach (MethodInfo mi in type.GetMethods ()) { if (!isScriptable && !mi.IsDefined (typeof(ScriptableMemberAttribute), true)) continue; RegisterScriptableMethod (mi); if (RegisterScriptableTypes (mi)) HasTypes = true; } if (HasTypes) { TypeOps typeOps = new TypeOps (); Type typeOpsType = typeof (TypeOps); RegisterBuiltinScriptableMethod (typeOpsType.GetMethod ("CreateManagedObject"), "createManagedObject", typeOps); } if (HasEvents) { EventOps eventOps = new EventOps (this); Type eventOpsType = typeof (EventOps); RegisterBuiltinScriptableMethod (eventOpsType.GetMethod ("AddEventListener"), "addEventListener", eventOps); RegisterBuiltinScriptableMethod (eventOpsType.GetMethod ("RemoveEventListener"), "removeEventListener", eventOps); } RegisterScriptableMethod (type.GetMethod ("ToString"), "toString"); if (ManagedObject is IList) { if (type.GetProperty ("Length") != null) RegisterScriptableProperty (type.GetProperty ("Length"), "length"); else if (type.GetProperty ("Count") != null) RegisterScriptableProperty (type.GetProperty ("Count"), "length"); foreach (MethodInfo mi in type.GetMethods ()) { switch (mi.Name) { case "IndexOf": RegisterScriptableMethod (mi, "indexOf"); break; case "LastIndexOf": RegisterScriptableMethod (mi, "lastIndexOf"); break; case "ToArray": RegisterScriptableMethod (mi, "toArray"); break; } } ListOps listOps = new ListOps ((IList)ManagedObject); Type listOpsType = typeof (ListOps); if (type.GetProperty ("Item") != null) RegisterScriptableProperty (type.GetProperty ("Item"), "item"); else RegisterScriptableProperty (listOpsType.GetProperty ("Item"), "item", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Pop"), "pop", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Push"), "push", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Reverse"), "reverse", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Shift"), "shift", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Unshift"), "unshift", listOps); RegisterScriptableMethod (listOpsType.GetMethod ("Splice"), "splice", listOps); } else if (ManagedObject is IDictionary) { DictOps dictOps = new DictOps ((IDictionary)ManagedObject); Type dictOpsType = typeof (DictOps); RegisterScriptableProperty (dictOpsType.GetProperty ("Item"), "item", dictOps); } }