public void ExampleTest2() { int[][] rectangle = { new[] { 1, 1, 1 }, new[] { 2, 2, 2 }, new[] { 3, 3, 3 }, }; var sq = new SubrectangleQueries(rectangle); // The initial rectangle (3x3) looks like: // 1 1 1 // 2 2 2 // 3 3 3 Assert.Equal(1, sq.GetValue(0, 0)); sq.UpdateSubrectangle(0, 0, 2, 2, 100); // After this update the rectangle looks like: // 100 100 100 // 100 100 100 // 100 100 100 Assert.Equal(100, sq.GetValue(0, 0)); Assert.Equal(100, sq.GetValue(2, 2)); sq.UpdateSubrectangle(1, 1, 2, 2, 20); // After this update the rectangle looks like: // 100 100 100 // 100 20 20 // 100 20 20 Assert.Equal(20, sq.GetValue(2, 2)); }
//Expected 5 public bool Execute() { var matrix = new int[][] { new int[] { 1, 2, 1 }, new int[] { 4, 3, 4 }, new int[] { 3, 2, 1 }, new int[] { 1, 1, 1 } }; var recQuer = new SubrectangleQueries(matrix); recQuer.UpdateSubrectangle(0, 0, 3, 2, 5); return(recQuer.GetValue(0, 2) == 5); }
public void Example2() { // Given var initialValue = new[] { new[] { 1, 1, 1 }, new[] { 2, 2, 2 }, new[] { 3, 3, 3 } }; // When var sut = new SubrectangleQueries(initialValue); var result1 = sut.GetValue(0, 0); sut.UpdateSubrectangle(0, 0, 2, 2, 100); var result2 = sut.GetValue(0, 0); var result3 = sut.GetValue(2, 2); sut.UpdateSubrectangle(1, 1, 2, 2, 20); var result4 = sut.GetValue(2, 2); // Then result1.Should().Be(1); result2.Should().Be(100); result3.Should().Be(100); result4.Should().Be(20); }
public void ExampleTest1() { int[][] rectangle = { new[] { 1, 2, 1 }, new[] { 4, 3, 4 }, new[] { 3, 2, 1 }, new[] { 1, 1, 1 } }; var sq = new SubrectangleQueries(rectangle); // The initial rectangle (4x3) looks like: // 1 2 1 // 4 3 4 // 3 2 1 // 1 1 1 Assert.Equal(1, sq.GetValue(0, 2)); // return 1 sq.UpdateSubrectangle(0, 0, 3, 2, 5); // After this update the rectangle looks like: // 5 5 5 // 5 5 5 // 5 5 5 // 5 5 5 Assert.Equal(5, sq.GetValue(0, 2)); // return 5 Assert.Equal(5, sq.GetValue(3, 1)); // return 5 sq.UpdateSubrectangle(3, 0, 3, 2, 10); // After this update the rectangle looks like: // 5 5 5 // 5 5 5 // 5 5 5 // 10 10 10 Assert.Equal(10, sq.GetValue(3, 1)); // return 10 Assert.Equal(5, sq.GetValue(0, 2)); // return 5 }
public void Example1() { // Given var initialValue = new[] { new[] { 1, 2, 1 }, new[] { 4, 3, 4 }, new[] { 3, 2, 1 }, new[] { 1, 1, 1 } }; // When var sut = new SubrectangleQueries(initialValue); var result1 = sut.GetValue(0, 2); sut.UpdateSubrectangle(0, 0, 3, 2, 5); var result2 = sut.GetValue(0, 2); var result3 = sut.GetValue(3, 1); sut.UpdateSubrectangle(3, 0, 3, 2, 10); var result4 = sut.GetValue(3, 1); var result5 = sut.GetValue(0, 2); // Then result1.Should().Be(1); result2.Should().Be(5); result3.Should().Be(5); result4.Should().Be(10); result5.Should().Be(5); }
private void ParseWithReflection(SubrectangleQueries solution, string[] methods, string paramethersJson, string resultsJson) { var paramethers = JsonConvert.DeserializeObject <List <int[]> >(paramethersJson); var results = JsonConvert.DeserializeObject <List <object> >(resultsJson); solution = new SubrectangleQueries(new int[][] { new int[] { 1, 2, 1 }, new int[] { 4, 3, 4 }, new int[] { 3, 2, 1 }, new int[] { 1, 1, 1 } }); var thisType = solution.GetType(); int index = -1; foreach (var method in methods) { if (index == -1) { index++; continue; } char[] arr = method.ToCharArray(); arr[0] = char.ToUpper(arr[0]); var theMethod = thisType.GetMethod(new string(arr)); var obj = new object?[0] { }; if (paramethers[index].Length > 1) { obj = new object?[paramethers[index].Length]; for (int i = 0; i < paramethers[index].Length; i++) { obj[i] = paramethers[index]?[i]; } } var result = theMethod.Invoke(solution, obj); if (results[index] != null) { if (results[index].GetType() == typeof(int)) { int res = (int)results[index]; Assert.AreEqual(res, (int)result); if (res != (int)result) { throw new NullReferenceException("Failed"); } } if (results[index].GetType() == typeof(long)) { long res = (long)results[index]; Assert.AreEqual(res, (int)result); if (res != (int)result) { throw new NullReferenceException("Failed"); } } if (results[index].GetType() == typeof(bool)) { bool res = (bool)results[index]; Assert.AreEqual(res, (bool)result); if (res != (bool)result) { throw new NullReferenceException("Failed"); } } } index++; } }