public static void WriteStackTOfStackT() { Stack <Stack <int> > input = new Stack <Stack <int> >(new List <Stack <int> > { new Stack <int>(new List <int>() { 1, 2 }), new Stack <int>(new List <int>() { 3, 4 }) }); string json = JsonSerializer.Serialize(input); Assert.Equal("[[4,3],[2,1]]", json); GenericStackWrapper <StringStackWrapper> input2 = new GenericStackWrapper <StringStackWrapper>(new List <StringStackWrapper> { new StringStackWrapper(new List <string>() { "1", "2" }), new StringStackWrapper(new List <string>() { "3", "4" }) }); json = JsonSerializer.Serialize(input2); Assert.Equal(@"[[""4"",""3""],[""2"",""1""]]", json); }
public static void ReadGenericStackOfArray() { Stack <int[]> result = JsonSerializer.Deserialize <Stack <int[]> >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 3; foreach (int[] arr in result) { foreach (int i in arr) { Assert.Equal(expected++, i); } expected = 1; } GenericStackWrapper <string[]> result2 = JsonSerializer.Deserialize <GenericStackWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 3; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } expected = 1; } }
public static void StackTOfStackT() { Stack <Stack <int> > result = JsonSerializer.Deserialize <Stack <Stack <int> > >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 4; foreach (Stack <int> st in result) { foreach (int i in st) { Assert.Equal(expected--, i); } } GenericStackWrapper <StringStackWrapper> result2 = JsonSerializer.Deserialize <GenericStackWrapper <StringStackWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 4; foreach (StringStackWrapper st in result2) { foreach (string str in st) { Assert.Equal($"{expected--}", str); } } }
public async Task WriteGenericStackOfStack() { Stack <Stack> input = new Stack <Stack>(); input.Push(new Stack(new List <int>() { 1, 2 })); input.Push(new Stack(new List <int>() { 3, 4 })); string json = await Serializer.SerializeWrapper(input); Assert.Equal("[[4,3],[2,1]]", json); GenericStackWrapper <StackWrapper> input2 = new GenericStackWrapper <StackWrapper>(); input2.Push(new StackWrapper(new List <object> { 1, 2 })); input2.Push(new StackWrapper(new List <object> { 3, 4 })); json = await Serializer.SerializeWrapper(input2); Assert.Equal("[[4,3],[2,1]]", json); }
public async Task ReadGenericStackOfArray() { Stack <int[]> result = await Serializer.DeserializeWrapper <Stack <int[]> >(@"[[1,2],[3,4]]"); int expected = 3; foreach (int[] arr in result) { foreach (int i in arr) { Assert.Equal(expected++, i); } expected = 1; } GenericStackWrapper <string[]> result2 = await Serializer.DeserializeWrapper <GenericStackWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 3; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } expected = 1; } }
public async Task StackTOfStackT() { Stack <Stack <int> > result = await Serializer.DeserializeWrapper <Stack <Stack <int> > >(@"[[1,2],[3,4]]"); int expected = 4; foreach (Stack <int> st in result) { foreach (int i in st) { Assert.Equal(expected--, i); } } GenericStackWrapper <StringStackWrapper> result2 = await Serializer.DeserializeWrapper <GenericStackWrapper <StringStackWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 4; foreach (StringStackWrapper st in result2) { foreach (string str in st) { Assert.Equal($"{expected--}", str); } } }