public void EvenNumbersFilterTest() { list = ListFunctions.Filter(list, x => (x % 2 == 0)); var result = new List <int>() { 2, 4, 6, 8, 10 }; Assert.AreEqual(result, list); }
public void PowerMapTest() { list = ListFunctions.Map(list, x => x * x); var result = new List <int>() { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 }; Assert.AreEqual(result, list); }
public void TestToStringConverter() { ListFunctions <int> listFunctions = new ListFunctions <int>(); string expected = "8"; listFunctions.AddList(8); string actual = listFunctions.ToString(); Assert.AreEqual(expected, actual); }
public void FoldFirstTest() { var myResult = ListFunctions.Fold(list, 0, (acc, elem) => acc + elem); int result = 0; foreach (var i in list) { result += i; } Assert.AreEqual(result, myResult); }
public List <GroupViewModel> GetAllGroups() { List <GroupModel> groupModel = new List <GroupModel>(); using (var context = new DataBaseContext()) { foreach (var group in context.GroupModels) { groupModel.Add(group); } } return(ListFunctions.ListGroupMToListGroupMV(groupModel)); }
public void CountArrayLength() { ListFunctions <string> listFunctions = new ListFunctions <string>(); int expected = 5; listFunctions.AddList("6"); listFunctions.AddList("3"); listFunctions.AddList("4"); listFunctions.AddList("6"); listFunctions.AddList("8"); int actual = listFunctions.CountArrayLength(); Assert.AreEqual(expected, actual); }
public void FilterFirstTest() { var newList = ListFunctions.Filter(list, i => i % 2 == 1); Assert.AreEqual(5, newList.Count); foreach (var i in list) { if (i % 2 == 1) { Assert.AreEqual(i, newList[(i - 1) / 2]); } } }
public void TestIndexerForString() { ListFunctions <string> listFunctions = new ListFunctions <string>(); string expected = "World"; listFunctions.AddList("Hello"); listFunctions.AddList("World"); listFunctions.AddList("!"); string actual = listFunctions[1]; Assert.AreEqual(expected, actual); }
//Randomly places a new dungeon room next to one that already exists private static void PlaceRandomRoom(Dungeon Dungeon) { //Get a random size for the new room Vector2 RoomSize = GetNewRoomSize(Dungeon.RoomSizes); //Create a shuffled copy of the list of rooms that already exist in the dungeon List <DungeonRoom> RoomsCopy = ListFunctions.Copy(Dungeon.Rooms); ListFunctions.Shuffle(RoomsCopy); //Search through the rooms, checking if we can place the new room adjacent to any of these existing rooms foreach (DungeonRoom OtherRoom in RoomsCopy) { //Make a list of the 4 placement directions we want to check for placing the new room List <Direction> Directions = new List <Direction>(); for (int i = 0; i < 4; i++) { Directions.Add((Direction)i); } ListFunctions.Shuffle(Directions); //Use each direction to check if we can place the new room next to the current OtherRoom in that direction Direction Placement = Direction.North; bool Found = false; foreach (Direction Check in Directions) { //Store the direction and exit out once a valid placement location has been found if (CanPlaceRoom(Dungeon, RoomSize, OtherRoom, Check)) { Placement = Check; Found = true; break; } } //Add the new room to the dungeon if a valid placement location was found if (Found) { Vector2 NewRoomPos = OtherRoom.GetAdjacentLocation((int)RoomSize.x, (int)RoomSize.y, Placement); DungeonRoom NewRoom = new DungeonRoom((int)RoomSize.x, (int)RoomSize.y, NewRoomPos); NewRoom.Init(); Dungeon.Rooms.Add(NewRoom); ConnectRooms(Dungeon, OtherRoom, NewRoom, Placement); return; return; } } }
public void TestIndexerForInt() { ListFunctions <int> listFunctions = new ListFunctions <int>(); int expected = 37; listFunctions.AddList(1); listFunctions.AddList(54); listFunctions.AddList(37); listFunctions.AddList(82759291); int actual = listFunctions[2]; Assert.AreEqual(expected, actual); }
public void TestMethodAddString() { ListFunctions <string> listFunctions = new ListFunctions <string>(); string elementToAdd = "Hello."; string expected = "Hello."; listFunctions.AddList("6"); listFunctions.AddList("3"); listFunctions.AddList("4"); listFunctions.AddList(elementToAdd); listFunctions.AddList("8"); string actual = listFunctions.MyArray[3]; Assert.AreEqual(expected, actual); }
public void TestMethodRemoveIndex() { ListFunctions <int> listFunctions = new ListFunctions <int>(); listFunctions.AddList(5); listFunctions.AddList(4); listFunctions.AddList(6); listFunctions.AddList(7); listFunctions.AddList(13); listFunctions.RemovedList(4); int expected = 5; int actual = listFunctions.CountArrayLength(); Assert.AreEqual(expected, actual); }
List <int> ProcessRawBytesFromUsb(List <byte> bytes) { int lastAddedCode = -1; bool errorDetected = false; var res = new List <int>(); for (int i = 0; i < bytes.Count - 3; i++) { if (bytes[i] < flagConst && bytes[i + 1] < flagConst && bytes[i + 2] >= flagConst) { bytes[i + 2] -= flagConst; var adcCode = (bytes[i + 2] << 14) | (bytes[i + 1] << 7) | bytes[i]; if (errorDetected) { var preprelastValue = res[res.Count - 2]; res[res.Count - 1] = lastAddedCode = (int)((adcCode + preprelastValue) / 2); errorDetected = false; } if (lastAddedCode != -1 && Math.Abs(lastAddedCode - adcCode) > 1) { errorDetected = true; } i += 2; res.Add(adcCode); lastAddedCode = adcCode; } else { errorCount++; } } var indexMin = ListFunctions.GetMinIndex(res); var indexMax = ListFunctions.GetMaxIndexAfterMin(res, indexMin); res = res.GetRange(indexMin, indexMax - indexMin); return(res); }
public List <UserViewModel> GetAllUsers() { List <UserModel> userModel = new List <UserModel>(); using (var context = new DataBaseContext()) { //context.UserModels.Add(userModel); //context.SaveChanges(); foreach (var user in context.UserModels) { userModel.Add(user); } } return(ListFunctions.ListUserMToListUserMV(userModel)); //return ListFunctions.ListUserMToListUserMV(_dataBaseMemory.UserModelList); throw new NotImplementedException(); }
public void TestMethodAddInt() { // Arrange ListFunctions <int> listFunctions = new ListFunctions <int>(); int elementToAdd = 6; int expected = 8; // Act listFunctions.AddList(elementToAdd); listFunctions.AddList(elementToAdd); listFunctions.AddList(elementToAdd); listFunctions.AddList(elementToAdd); listFunctions.AddList(8); int actual = listFunctions.MyArray[4]; // Assert Assert.AreEqual(expected, actual); }
private static void SetupBuiltInModules() { // Была мысль как-то ещё поделить, но я не придумал как... // Все эти функции - основа языка _builtInModulesActivators.Add("lang", context => { ListFunctions.Define(context); ListSugarFunctions.Define(context); ControlFunctions.Define(context); TypePredicateFunctions.Define(context); }); // Более того, следующие три набора функций так же можно было бы объединить с lang... // Но я их всё же вынес, потому как язык может работать и без них _builtInModulesActivators.Add("context", ContextFunctions.Define); _builtInModulesActivators.Add("console", ConsoleFunctions.Define); _builtInModulesActivators.Add("math", MathFunctions.Define); // А вот этот модуль вполне удобно иметь отдельным, потому как тогда имена его функций упрощаются _builtInModulesActivators.Add("table", TableFunctions.Define); }
public void AlternatingSumFoldTest() { var foldedList = ListFunctions.Fold(list, 0, (acc, elem) => acc + (int)Math.Pow(-1, elem) * elem); Assert.AreEqual(5, foldedList); }
public void SumFolderTest() { var foldedList = ListFunctions.Fold(list, 0, (acc, elem) => acc + elem); Assert.AreEqual(55, foldedList); }
public void SomeFilterTest() { list = ListFunctions.Filter(list, x => (x == 5)); Assert.IsTrue(list.Count == 1); Assert.IsTrue(list.Contains(5)); }
protected List <Node> Nodes = new List <Node>(); //The child nodes for this selector public SelectorNode(List <Node> Nodes) { this.Nodes = ListFunctions.Copy(Nodes); }
public void FilterSecondTest() { var newList = ListFunctions.Filter(list, i => false); Assert.AreEqual(0, newList.Count); }
public void IdentityMapTest() { var result = ListFunctions.Map(list, x => x); Assert.AreEqual(list, result); }
public void FoldSecondTest() { var myResult = ListFunctions.Fold(list, 42, (acc, elem) => acc); Assert.AreEqual(42, myResult); }
private static bool IsReallyAFlat(IEnumerable <PolygonalFace> faces) { return(ListFunctions.FacesWithDistinctNormals(faces.ToList()).Count == 1); }
private static bool IsReallyACone(IEnumerable <PolygonalFace> facesAll, out double[] axis, out double coneAngle) { var faces = ListFunctions.FacesWithDistinctNormals(facesAll.ToList()); var n = faces.Count; if (faces.Count <= 1) { axis = null; coneAngle = double.NaN; return(false); } if (faces.Count == 2) { axis = faces[0].Normal.crossProduct(faces[1].Normal).normalize(); coneAngle = 0.0; return(false); } // a simpler approach: if the cross product of the normals are all parallel, it's a cylinder, // otherwise, cone. /*var r = new Random(); * var rndList = new List<int>(); * var crossProd = new List<double[]>(); * var c = 0; * while (c < 20) * { * var ne = r.Next(facesAll.Count); * if (!rndList.Contains(ne)) rndList.Add(ne); * c++; * } * for (var i = 0; i < rndList.Count-1; i++) * { * for (var j = i + 1; j < rndList.Count; j++) * { * crossProd.Add(facesAll[i].Normal.crossProduct(facesAll[j].Normal).normalize()); * } * } * axis = crossProd[0]; * coneAngle = 0.0; * for (var i = 0; i < crossProd.Count - 1; i++) * { * for (var j = i + 1; j < crossProd.Count; j++) * { * if (Math.Abs(crossProd[i].dotProduct(crossProd[j]) - 1) < 0.00000008) return true; * } * } * return false;*/ // find the plane that the normals live on in the Gauss sphere. If it is not // centered at 0 then you have a cone. // since the vectors that are the difference of two normals (v = n1 - n2) would // be in the plane, let's first figure out the average plane of this normal var inPlaneVectors = new double[n][]; inPlaneVectors[0] = faces[0].Normal.subtract(faces[n - 1].Normal); for (int i = 1; i < n; i++) { inPlaneVectors[i] = faces[i].Normal.subtract(faces[i - 1].Normal); } var normalsOfGaussPlane = new List <double[]>(); var tempCross = inPlaneVectors[0].crossProduct(inPlaneVectors[n - 1]).normalize(); if (!tempCross.Any(double.IsNaN)) { normalsOfGaussPlane.Add(tempCross); } for (int i = 1; i < n; i++) { tempCross = inPlaneVectors[i].crossProduct(inPlaneVectors[i - 1]).normalize(); if (!tempCross.Any(double.IsNaN)) { if (tempCross.dotProduct(normalsOfGaussPlane[0]) >= 0) { normalsOfGaussPlane.Add(tempCross); } else { normalsOfGaussPlane.Add(tempCross.multiply(-1)); } } } var normalOfGaussPlane = new double[3]; normalOfGaussPlane = normalsOfGaussPlane.Aggregate(normalOfGaussPlane, (current, c) => current.add(c)); normalOfGaussPlane = normalOfGaussPlane.divide(normalsOfGaussPlane.Count); var distance = faces.Sum(face => face.Normal.dotProduct(normalOfGaussPlane)); if (distance < 0) { axis = normalOfGaussPlane.multiply(-1); distance = -distance / n; } else { distance /= n; axis = normalOfGaussPlane; } coneAngle = Math.Asin(distance); return(Math.Abs(distance) >= ClassificationConstants.MinConeGaussPlaneOffset); }
protected List <Node> Nodes = new List <Node>(); //Children nodes belonging to this sequence public SequenceNode(List <Node> Nodes) { this.Nodes = ListFunctions.Copy(Nodes); }