public void CompareTest_Double_Similar() { var leftDouble = 1.5e7; var rightDouble = leftDouble * 0.99; var dataTable = TestHelper.MockDataTable(withData: false); var leftRow = dataTable.NewRow(); var rightRow = dataTable.NewRow(); leftRow["double"] = leftDouble; rightRow["double"] = rightDouble; var field = new Field { Name = "double", IsKey = false, FieldType = typeof(double), Gap = 0.02 }; var expected = FieldCompareResult.Similar; var actual = FieldCompare.Compare(leftRow, rightRow, field); Assert.AreEqual(expected, actual); }
public void FieldCompareMapTest() { { ImmutableDictionary <Int32, String> aDict = ImmutableDictionary <int, string> .Empty; aDict = aDict.Add(1, "abc"); aDict = aDict.Add(2, "def"); Assert.True(FieldCompare.CompareMap <Int32, String>(aDict, aDict) == 0); } { ImmutableDictionary <Int32, String> aDict = ImmutableDictionary <int, string> .Empty; aDict = aDict.Add(1, "abc"); aDict = aDict.Add(2, "def"); ImmutableDictionary <Int32, String> bDict = ImmutableDictionary <int, string> .Empty; bDict = bDict.Add(1, "abc"); Assert.True(FieldCompare.CompareMap <Int32, String>(aDict, bDict) > 0); Assert.True(FieldCompare.CompareMap <Int32, String>(bDict, aDict) < 0); } { ImmutableDictionary <Int32, String> aDict = ImmutableDictionary <int, string> .Empty; aDict = aDict.Add(1, "abc"); aDict = aDict.Add(2, "def"); ImmutableDictionary <Int32, String> bDict = ImmutableDictionary <int, string> .Empty; bDict = bDict.Add(2, "abc"); bDict = bDict.Add(1, "def"); Assert.True(FieldCompare.CompareMap <Int32, String>(aDict, bDict) < 0); Assert.True(FieldCompare.CompareMap <Int32, String>(bDict, aDict) > 0); } }
public void SemanticVersionDTOFieldsTest() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; Misc.Compare(dtoStart.PublicId, Misc.g1, Misc.g2, Misc.g3, Misc.g4); Assert.True(dtoStart.StampDTO.CompareTo(Misc.CreateStampDTO) == 0); FieldCompare.Same(dtoStart.Fields, new Object[] { 1, "abcdef", 0.3F }); }
private string getFieldType(FieldCompare fieldInfo) { string fieldType = fieldInfo.data_type; if (fieldInfo.width > 0) { if (fieldInfo.DecimalPrecision > 0) { fieldType = string.Format(fieldType + "({0},{1})", fieldInfo.width, fieldInfo.DecimalPrecision); } else { fieldType = string.Format(fieldType + "({0})", fieldInfo.width); } } return(fieldType); }
public void GraphDTOMarshalTest() { GraphDTO dtoStart = Misc.CreateGraphDTO(); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.MarshalVertexMap(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { ImmutableList <VertexDTO> dtoRead = GraphDTO.UnmarshalVertexMap(input); Assert.True(FieldCompare.CompareSequence(dtoRead, dtoStart.VertexMap) == 0); } }
public void FieldCompareTest() { { Assert.True(FieldCompare.Same("abc", "abc")); Assert.False(FieldCompare.Same("abc", "abcd")); } { Assert.True(FieldCompare.Same(0, 0)); Assert.False(FieldCompare.Same(0, 1)); } { Assert.True(FieldCompare.Same(0.1F, 0.1F)); Assert.False(FieldCompare.Same(0.0F, 1.0F)); } { Assert.True(FieldCompare.Same(true, true)); Assert.False(FieldCompare.Same(true, false)); } { Assert.True(FieldCompare.Same(new DateTime(2020, 1, 1), new DateTime(2020, 1, 1))); Assert.False(FieldCompare.Same(new DateTime(2020, 1, 1), new DateTime(2020, 2, 1))); } { Assert.True(FieldCompare.Same(new byte[] { 1, 2, 3 }, new byte[] { 1, 2, 3 })); Assert.False(FieldCompare.Same(new byte[] { 1, 2, 3 }, new byte[] { 1, 3, 2 })); } { Assert.True(FieldCompare.Same(Misc.CreateConceptChronologyDTO, Misc.CreateConceptChronologyDTO)); Assert.False(FieldCompare.Same( Misc.CreateConceptChronologyDTO, Misc.CreateConceptChronologyDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }));
public void CompareTest_DateTime_QuiteDifferent() { var leftDateTime = DateTime.Now; var rightDateTime = DateTime.Now.AddDays(-1); var dataTable = TestHelper.MockDataTable(withData: false); var leftRow = dataTable.NewRow(); var rightRow = dataTable.NewRow(); leftRow["datetime"] = leftDateTime; rightRow["datetime"] = rightDateTime; var field = new Field { Name = "datetime", IsKey = false, FieldType = typeof(DateTime) }; var expected = FieldCompareResult.QuiteDifferent; var actual = FieldCompare.Compare(leftRow, rightRow, field); Assert.AreEqual(expected, actual); }
public void CompareIdenticalDateTimeThenSuccess() { var leftDateTime = DateTime.Now; var rightDateTime = leftDateTime; var dataTable = TestHelper.MockDataTable(withData: false); var leftRow = dataTable.NewRow(); var rightRow = dataTable.NewRow(); leftRow["datetime"] = leftDateTime; rightRow["datetime"] = rightDateTime; var field = new Field { Name = "datetime", IsKey = false, FieldType = typeof(DateTime) }; var expected = FieldCompareResult.Identical; var actual = FieldCompare.Compare(leftRow, rightRow, field); Assert.AreEqual(expected, actual); }
public void FieldCompare() { //ExStart //ExFor:FieldCompare //ExFor:FieldCompare.ComparisonOperator //ExFor:FieldCompare.LeftExpression //ExFor:FieldCompare.RightExpression //ExSummary:Shows how to insert a field that compares expressions. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a compare field using a document builder FieldCompare field = (FieldCompare)builder.InsertField(FieldType.FieldCompare, true); // Construct a comparison statement field.LeftExpression = "3"; field.ComparisonOperator = "<"; field.RightExpression = "2"; // The compare field will print a "0" or "1" depending on the truth of its statement // The result of this statement is false, so a "0" will be show up in the document Assert.AreEqual(" COMPARE 3 < 2", field.GetFieldCode()); builder.Writeln(); // Here a "1" will show up, because the statement is true field = (FieldCompare)builder.InsertField(FieldType.FieldCompare, true); field.LeftExpression = "5"; field.ComparisonOperator = "="; field.RightExpression = "2 + 3"; Assert.AreEqual(" COMPARE 5 = \"2 + 3\"", field.GetFieldCode()); doc.UpdateFields(); doc.Save(MyDir + @"\Artifacts\Field.Compare.docx"); }
//设置行 private void export(DataDictCompare dataDictCompare) { //获取枚举类 List <FieldCompare> dataDictList = dataDictCompare.FieldCompareList; //新增字段 var createdFieldList = dataDictList.Where(t => t.FieldStatus == FieldStatusEnum.Created).ToList(); if (createdFieldList.Count > 0) { // 创建新增行 for (var i = _row; i < createdFieldList.Count + _row; i++) { FieldCompare fieldInfo = createdFieldList[i - _row]; IRow row1 = _sheet2.CreateRow(i); //新建单元格 ICell cell = row1.CreateCell(0); // 单元格赋值 cell.SetCellValue("新增字段"); cell.CellStyle = titleStyle; //新建单元格-字段名称 ICell cell1 = row1.CreateCell(1); cell1.SetCellValue(fieldInfo.field_name); cell1.CellStyle = borderStyle; //新建单元格-字段类型 ICell cell2 = row1.CreateCell(2); string fieldType = getFieldType(fieldInfo); cell2.SetCellValue(fieldType); cell2.CellStyle = borderStyle; //新建单元格-字段中文名称 ICell cell3 = row1.CreateCell(3); cell3.SetCellValue(fieldInfo.field_name_c); cell3.CellStyle = borderStyle; } _row += createdFieldList.Count; } //更新字段 var updatedFieldList = dataDictList.Where(t => t.FieldStatus == FieldStatusEnum.Update).ToList(); if (updatedFieldList.Count > 0) { // 创建新增行 for (var i = _row; i < updatedFieldList.Count + _row; i++) { FieldCompare fieldInfo = updatedFieldList[i - _row]; IRow row1 = _sheet2.CreateRow(i); //新建单元格 ICell cell = row1.CreateCell(0); // 单元格赋值 cell.SetCellValue("更新字段"); cell.CellStyle = titleStyle; //新建单元格-字段名称 ICell cell1 = row1.CreateCell(1); cell1.SetCellValue(fieldInfo.field_name); cell1.CellStyle = borderStyle; //新建单元格-字段类型 ICell cell2 = row1.CreateCell(2); string fieldType = getFieldType(fieldInfo); cell2.SetCellValue(fieldType); cell2.CellStyle = borderStyle; //新建单元格-字段中文名称 ICell cell3 = row1.CreateCell(3); cell3.SetCellValue(fieldInfo.field_name_c); cell3.CellStyle = borderStyle; } _row += updatedFieldList.Count; } //删除字段 var deletedFieldList = dataDictList.Where(t => t.FieldStatus == FieldStatusEnum.Deleted).ToList(); if (deletedFieldList.Count > 0) { // 创建新增行 for (var i = _row; i < deletedFieldList.Count + _row; i++) { FieldCompare fieldInfo = deletedFieldList[i - _row]; IRow row1 = _sheet2.CreateRow(i); //新建单元格 ICell cell = row1.CreateCell(0); // 单元格赋值 cell.SetCellValue("删除字段"); cell.CellStyle = titleStyle; //新建单元格-字段名称 ICell cell1 = row1.CreateCell(1); cell1.SetCellValue(fieldInfo.field_name); cell1.CellStyle = borderStyle; //新建单元格-字段类型 ICell cell2 = row1.CreateCell(2); string fieldType = getFieldType(fieldInfo); cell2.SetCellValue(fieldType); cell2.CellStyle = borderStyle; //新建单元格-字段中文名称 ICell cell3 = row1.CreateCell(3); cell3.SetCellValue(fieldInfo.field_name_c); cell3.CellStyle = borderStyle; } _row += deletedFieldList.Count; } _row += 2; }