//public static void HoleTest() //{ // var Persons = DbMaker.Make<Person, string>( // (person) => person.Name,false); // var PersonById = Persons.MakeUniqueKey((c) => c.id); // var Products = DbMaker.Make<Product, string>( // (Product) => Product.Name,false); // Products.AddRelation((c) => c.Person, Persons, (c) => c.Product);//1 to 1 // Products.AddRelation((c) => c.Persons,false, Persons, (c) => c.Products,false);//m to n // Products.AddRelation((c) => c.Person2, Persons, (c) => c.Products2,false);// 1 to n // Persons.Delete(); // Products.Delete(); // Products.Insert(new Product() { Name = "p1" }); // Products.Update((c) => c.Name = "p1", (c) => c.Persons.Insert(new Person() { Name = "ali", id = 12 }));//m to n // Products.Update((c) => c.Name = "p1", (c) => c.ToString()); // Products.Update((c) => c.Name = "p1", (c) => c.Person.Value = Persons.GetItem(new Person() { Name = "ali" }));//1 to 1 // Products.Update((c) => c.Name = "p1", (c) => c.Person2.Value = Persons.GetItem(new Person() { Name = "ali" }));//n to 1 // var Ipr = Products.First(); // var Ips = Persons.First(); // Console.WriteLine(Ipr.Person.Value.Name); // Console.WriteLine(Ips.Product.Value.Name); // Console.WriteLine(Ips.Products.First().Name); // Console.WriteLine(Ipr.Persons.First().Name); // PersonById.Insert(new Person() { Name = "ala", id = 13 }); // //Persons.Delete(new Person() { Name = "ahmad" }); // var psid = PersonById.GetItem(new Person() { id = 12 }); // Console.ReadKey(); //} public static void PerformanceTest() { var Persons = new ArrayTable <Person, string>( (person) => person.Name, false); var Count = 10000; var InsertTime = Monsajem_Incs.TimeingTester.Timing.run(() => { for (int i = 0; i < Count; i++) { Persons.Insert((c) => c.Name = i.ToString()); } }); var UpdateTime = Monsajem_Incs.TimeingTester.Timing.run(() => { for (int i = 0; i < Count; i++) { Persons.Update((c) => c.Name = i.ToString(), (c) => c.id = i); } }); var DeleteTime = Monsajem_Incs.TimeingTester.Timing.run(() => { for (int i = 0; i < Count; i++) { Persons.Delete((c) => c.Name = i.ToString()); } }); Console.ReadKey(); }
private void TestObjectAPI(ArrayTable a) { var b = a.UnPack(); AreEqual(a, b); var fbb = new FlatBufferBuilder(1); fbb.Finish(ArrayTable.Pack(fbb, b).Value); var c = ArrayTable.GetRootAsArrayTable(fbb.DataBuffer); AreEqual(a, c); var jsonText = b.SerializeToJson(); var d = ArrayTableT.DeserializeFromJson(jsonText); AreEqual(a, d); var fbBuffer = b.SerializeToBinary(); Assert.IsTrue(ArrayTable.ArrayTableBufferHasIdentifier(new ByteBuffer(fbBuffer))); var e = ArrayTableT.DeserializeFromBinary(fbBuffer); AreEqual(a, e); }
public void TestFixedLenghtArrays() { FlatBufferBuilder builder = new FlatBufferBuilder(100); float a; int[] b = new int[15]; sbyte c; int[,] d_a = new int[2, 2]; TestEnum[] d_b = new TestEnum[2]; TestEnum[,] d_c = new TestEnum[2, 2]; a = 0.5f; for (int i = 0; i < 15; i++) { b[i] = i; } c = 1; d_a[0, 0] = 1; d_a[0, 1] = 2; d_a[1, 0] = 3; d_a[1, 1] = 4; d_b[0] = TestEnum.B; d_b[1] = TestEnum.C; d_c[0, 0] = TestEnum.A; d_c[0, 1] = TestEnum.B; d_c[1, 0] = TestEnum.C; d_c[1, 1] = TestEnum.B; Offset <ArrayStruct> arrayOffset = ArrayStruct.CreateArrayStruct( builder, a, b, c, d_a, d_b, d_c); // Create a table with the ArrayStruct. ArrayTable.StartArrayTable(builder); ArrayTable.AddA(builder, arrayOffset); Offset <ArrayTable> tableOffset = ArrayTable.EndArrayTable(builder); ArrayTable.FinishArrayTableBuffer(builder, tableOffset); ArrayTable table = ArrayTable.GetRootAsArrayTable(builder.DataBuffer); Assert.AreEqual(table.A?.A, 0.5f); for (int i = 0; i < 15; i++) { Assert.AreEqual(table.A?.B(i), i); } Assert.AreEqual(table.A?.C, (sbyte)1); Assert.AreEqual(table.A?.D(0).A(0), 1); Assert.AreEqual(table.A?.D(0).A(1), 2); Assert.AreEqual(table.A?.D(1).A(0), 3); Assert.AreEqual(table.A?.D(1).A(1), 4); Assert.AreEqual(table.A?.D(0).B, TestEnum.B); Assert.AreEqual(table.A?.D(1).B, TestEnum.C); Assert.AreEqual(table.A?.D(0).C(0), TestEnum.A); Assert.AreEqual(table.A?.D(0).C(1), TestEnum.B); Assert.AreEqual(table.A?.D(1).C(0), TestEnum.C); Assert.AreEqual(table.A?.D(1).C(1), TestEnum.B); }
private void TestObjectAPI(ArrayTable a) { var b = a.UnPack(); AreEqual(a, b); var fbb = new FlatBufferBuilder(1); fbb.Finish(ArrayTable.Pack(fbb, b).Value); var c = ArrayTable.GetRootAsArrayTable(fbb.DataBuffer); AreEqual(a, c); }
public static void SimpleTest() { var Persons = new ArrayTable <Person, string>( (person) => person.Name, false); Persons.Insert((c) => c.Name = "babak"); Persons.Insert((c) => c.Name = "aal"); Persons.Insert((c) => c.Name = "ali"); Persons.Update((c) => c.Name = "aal", (c) => c.Name = "bba"); Persons.Update((c) => c.Name = "babak", (c) => c.Name = "abl"); Console.ReadKey(); }
public static void SafeTest() { var Persons = new ArrayTable <Person2, string>( (person) => person.Name, false); var count = 100000; Persons.ToArray(); Array <ActionOn> Actions = new Array <ActionOn>(); for (int i = 0; i < count; i++) { var Id = i; var CurrentAction = new ActionOn() { Id = Id }; CurrentAction.Insert = () => Persons.Insert((c) => c.Name = Id.ToString()); CurrentAction.Update = () => Persons.Update((c) => c.Name = Id.ToString(), (c) => c.id = Id); CurrentAction.Delete = () => Persons.Delete((c) => c.Name = Id.ToString()); Actions.Insert(CurrentAction); } Random random = new Random(); while (Actions.Length > 0) { var i = random.Next(0, Actions.Length - 1); var Ac = Actions[i]; if (Ac.Insert != null) { Ac.Insert(); Ac.Insert = null; } else if (Ac.Update != null) { Ac.Update(); Ac.Update = null; } else { Ac.Delete(); Actions.DeleteByPosition(i); } } Console.ReadKey(); }
public virtual void getColumnTypes() { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.google.common.collect.ArrayTable<int, int, com.opengamma.strata.collect.result.Result<?>> table = com.google.common.collect.ArrayTable.create(INDICES, INDICES); ArrayTable <int, int, Result <object> > table = ArrayTable.create(INDICES, INDICES); table.put(0, 0, Result.success(1)); table.put(0, 1, Result.success("abc")); table.put(1, 0, Result.success(2)); table.put(1, 1, Result.success("def")); IList <Type> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table)); assertThat(columnTypes).isEqualTo(ImmutableList.of(typeof(Integer), typeof(string))); }
public virtual void getColumnTypesWithAllFailures() { ImmutableList <int> indices = ImmutableList.of(0, 1); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.google.common.collect.ArrayTable<int, int, com.opengamma.strata.collect.result.Result<?>> table = com.google.common.collect.ArrayTable.create(indices, indices); ArrayTable <int, int, Result <object> > table = ArrayTable.create(indices, indices); table.put(0, 0, Result.failure(FailureReason.ERROR, "fail")); table.put(0, 1, Result.failure(FailureReason.ERROR, "fail")); table.put(1, 0, Result.failure(FailureReason.ERROR, "fail")); table.put(1, 1, Result.failure(FailureReason.ERROR, "fail")); IList <Type> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table)); assertThat(columnTypes).isEqualTo(ImmutableList.of(typeof(object), typeof(object))); }
private void TestObjectAPI(ArrayTable a) { var b = a.UnPack(); AreEqual(a, b); var fbb = new FlatBufferBuilder(1); fbb.Finish(ArrayTable.Pack(fbb, b).Value); var c = ArrayTable.GetRootAsArrayTable(fbb.DataBuffer); AreEqual(a, c); var jsonText = b.SerializeToJson(); var d = ArrayTableT.DeserializeFromJson(jsonText); AreEqual(a, d); }
private void AreEqual(ArrayTable a, ArrayTable b) { Assert.AreEqual(a.A.Value.A, b.A.Value.A); for (int i = 0; i < 15; ++i) { Assert.AreEqual(a.A.Value.B(i), b.A.Value.B(i)); } Assert.AreEqual(a.A.Value.C, b.A.Value.C); for (int i = 0; i < 2; ++i) { var ad = a.A.Value.D(i); var bd = b.A.Value.D(i); for (int j = 0; j < 2; ++j) { Assert.AreEqual(ad.A(j), bd.A(j)); } Assert.AreEqual(ad.B, bd.B); for (int j = 0; j < 2; ++j) { Assert.AreEqual(ad.C(j), bd.C(j)); } for (int j = 0; j < 2; ++j) { Assert.AreEqual(ad.D(j), bd.D(j)); } } Assert.AreEqual(a.A.Value.E, b.A.Value.E); for (int i = 0; i < 2; ++i) { Assert.AreEqual(a.A.Value.F(i), b.A.Value.F(i)); } }
private TradeReport report <T1>(ArrayTable <T1> table) { return(TradeReport.builder().columns(TradeReportColumn.builder().header("col0").build(), TradeReportColumn.builder().header("col1").build()).data(table).valuationDate(LocalDate.now(ZoneOffset.UTC)).runInstant(Instant.now()).build()); }