添加项目文件。
This commit is contained in:
142
CoordinateFormatTest.cs
Normal file
142
CoordinateFormatTest.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DrillTools;
|
||||
using DrillTools.Integration;
|
||||
|
||||
namespace DrillTools.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// 坐标格式保留测试类
|
||||
/// 用于验证修改后的代码能正确保留原始坐标格式
|
||||
/// </summary>
|
||||
public class CoordinateFormatTest
|
||||
{
|
||||
/// <summary>
|
||||
/// 测试坐标格式保留功能
|
||||
/// </summary>
|
||||
public static void TestCoordinateFormatPreservation()
|
||||
{
|
||||
Console.WriteLine("=== 坐标格式保留测试 ===");
|
||||
|
||||
// 测试用例:各种格式的坐标
|
||||
var testCases = new[]
|
||||
{
|
||||
"X-265000Y013250", // 负坐标,前导零
|
||||
"X-265000Y008250", // 负坐标,前导零
|
||||
"X075392Y559511", // 正坐标,前导零
|
||||
"X017500Y519500G85X018500Y519500", // 槽孔坐标
|
||||
"X-238500Y519500G85X-237500Y519500" // 负坐标槽孔
|
||||
};
|
||||
|
||||
// 创建测试钻带内容
|
||||
string drillTapeContent = CreateTestDrillTape(testCases);
|
||||
|
||||
// 解析钻带
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(drillTapeContent);
|
||||
|
||||
// 验证结果
|
||||
if (result.Success)
|
||||
{
|
||||
Console.WriteLine("钻带解析成功!");
|
||||
|
||||
// 检查每个工具的坐标输出
|
||||
foreach (var toolResult in result.ToolResults)
|
||||
{
|
||||
Console.WriteLine($"\n工具 T{toolResult.ToolNumber:D2} (直径: {toolResult.Diameter:F3}mm):");
|
||||
Console.WriteLine($"坐标数量: {toolResult.Locations.Count}");
|
||||
|
||||
// 显示前5个坐标作为示例
|
||||
int displayCount = Math.Min(5, toolResult.Locations.Count);
|
||||
for (int i = 0; i < displayCount; i++)
|
||||
{
|
||||
string original = i < testCases.Length ? testCases[i] : "N/A";
|
||||
string parsed = toolResult.Locations[i];
|
||||
Console.WriteLine($" 原始: {original}");
|
||||
Console.WriteLine($" 解析: {parsed}");
|
||||
Console.WriteLine($" 匹配: {(original == parsed ? "✓" : "✗")}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"钻带解析失败: {result.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建测试钻带内容
|
||||
/// </summary>
|
||||
private static string CreateTestDrillTape(string[] coordinates)
|
||||
{
|
||||
var drillTape = new System.Text.StringBuilder();
|
||||
|
||||
// 添加头部
|
||||
drillTape.AppendLine("M48");
|
||||
drillTape.AppendLine("METRIC");
|
||||
drillTape.AppendLine("VER,1");
|
||||
drillTape.AppendLine("FMAT,2");
|
||||
|
||||
// 添加刀具定义
|
||||
drillTape.AppendLine("T01C1.000");
|
||||
drillTape.AppendLine("T02C2.000");
|
||||
|
||||
// 添加结束标记
|
||||
drillTape.AppendLine("%");
|
||||
|
||||
// 添加刀具1的坐标
|
||||
drillTape.AppendLine("T01");
|
||||
for (int i = 0; i < Math.Min(3, coordinates.Length); i++)
|
||||
{
|
||||
// 只添加普通坐标(不含G85)
|
||||
if (!coordinates[i].Contains("G85"))
|
||||
{
|
||||
drillTape.AppendLine(coordinates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加刀具2的坐标(槽孔)
|
||||
drillTape.AppendLine("T02");
|
||||
for (int i = 3; i < coordinates.Length; i++)
|
||||
{
|
||||
// 添加槽孔坐标(含G85)
|
||||
if (coordinates[i].Contains("G85"))
|
||||
{
|
||||
drillTape.AppendLine(coordinates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加结束标记
|
||||
drillTape.AppendLine("M30");
|
||||
|
||||
return drillTape.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试Point2D的原始字符串保留功能
|
||||
/// </summary>
|
||||
public static void TestPoint2DOriginalString()
|
||||
{
|
||||
Console.WriteLine("\n=== Point2D原始字符串测试 ===");
|
||||
|
||||
// 测试用例
|
||||
var testCoordinates = new[]
|
||||
{
|
||||
"X-265000Y013250",
|
||||
"X075392Y559511",
|
||||
"X000123Y000456"
|
||||
};
|
||||
|
||||
foreach (var coord in testCoordinates)
|
||||
{
|
||||
var point = Point2D.ParseFromDrillString(coord);
|
||||
|
||||
Console.WriteLine($"原始坐标: {coord}");
|
||||
Console.WriteLine($"解析后X: {point.X:F3}, Y: {point.Y:F3}");
|
||||
Console.WriteLine($"原始字符串: {point.OriginalString}");
|
||||
Console.WriteLine($"字符串匹配: {(coord == point.OriginalString ? "✓" : "✗")}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user