using GraphTUI.Core.Models; using GraphTUI.Rendering; namespace GraphTUI.Tests; public static class ExportSessionTests { public static void Register(TestRunner runner) { runner.Add("Session: Save & Load Roundtrip", () => { var original = new SessionData { Viewport = new ViewportDto { XMin = -5, XMax = 5, YMin = -2, YMax = 2 }, Parameters = [ new ParameterDto { Name = "a", Value = 2.5, Min = -10, Max = 10, Step = 0.1 } ], Functions = [ new FunctionDto { Id = 1, Type = "Cartesian", Expression = "sin(a*x)", ColorR = 0, ColorG = 220, ColorB = 255, IsVisible = true } ] }; string json = SessionData.ToJson(original); Assert.True(!string.IsNullOrEmpty(json), "JSON should not be empty"); var loaded = SessionData.FromJson(json); Assert.True(loaded != null, "Loaded session should not be null"); Assert.Equal(-5.0, loaded!.Viewport.XMin); Assert.Equal(5.0, loaded.Viewport.XMax); Assert.Equal(1, loaded.Functions.Count); Assert.Equal("sin(a*x)", loaded.Functions[0].Expression); Assert.Equal(1, loaded.Parameters.Count); Assert.Equal(2.5, loaded.Parameters[0].Value); }); runner.Add("Export: SVG Output Format", () => { var vp = new Viewport { XMin = -10, XMax = 10, YMin = -5, YMax = 5 }; var fns = new List { new(1, "sin(x)", ColorRgb.Cyan), new(2, "cos(t)", ColorRgb.Magenta, FunctionType.Parametric, "sin(2t)") }; string svg = SvgExporter.Export(vp, fns, _ => 1.0, 800, 500); Assert.True(svg.Contains(""), "SVG should have closing tag"); Assert.True(svg.Contains("path fill=\"none\" stroke=\"rgb(0,220,255)\""), "SVG should contain path with function color"); }); runner.Add("Export: Text Braille Output", () => { var canvas = new BrailleCanvas(10, 5); canvas.DrawLine(0, 0, 19, 19, ColorRgb.White); string txt = TextExporter.Export(canvas); Assert.True(!string.IsNullOrEmpty(txt), "Text export should not be empty"); string[] lines = txt.Split('\n', StringSplitOptions.RemoveEmptyEntries); Assert.Equal(5, lines.Length); }); } }