chore: initial git load of code space

This commit is contained in:
Thom Lamb
2026-05-12 08:52:33 -05:00
parent 9abada692f
commit 5e467bcc9c
384 changed files with 65960 additions and 2 deletions
@@ -0,0 +1,279 @@
using Strata.SqlTools.SqlBreakdown.Expressions;
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional.Logical;
using Strata.SqlTools.SqlBreakdown.Expressions.Literals;
using Strata.SqlTools.Markdown.Expressions;
namespace Strata.SqlTools.Markdown.Tests.Expressions;
[TestFixture]
public class ExpressionGeneratorTests
{
private ExpressionGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new ExpressionGenerator();
}
[Test]
public void GenerateMarkdown_WithSimpleExpression_GeneratesMarkdown()
{
// Arrange
var expression = new NumberLiteralExpression(42);
// Act
var result = _generator.GenerateMarkdown(expression);
// Assert
Assert.That(result, Does.Contain("## Expression Structure"));
Assert.That(result, Does.Contain("## Expression Type"));
Assert.That(result, Does.Contain("## Mermaid Diagram"));
Assert.That(result, Does.Contain("NumberLiteralExpression"));
}
[Test]
public void GenerateMarkdown_WithComparisonExpression_IncludesComparison()
{
// Arrange
Expression left = new NumberLiteralExpression(100);
Expression right = new NumberLiteralExpression(50);
var expression = left > right;
// Act
var result = _generator.GenerateMarkdown(expression, "Price Comparison");
// Assert
Assert.That(result, Does.Contain("# Price Comparison"));
Assert.That(result, Does.Contain("Comparison"));
Assert.That(result, Does.Contain("```"));
}
[Test]
public void GenerateMarkdown_WithArithmeticExpression_IncludesArithmetic()
{
// Arrange
Expression price = new NumberLiteralExpression(100);
Expression discount = new NumberLiteralExpression(0.1m);
var expression = price * (1 - discount);
// Act
var result = _generator.GenerateMarkdown(expression);
// Assert
Assert.That(result, Does.Contain("Arithmetic"));
Assert.That(result, Does.Contain("```mermaid"));
Assert.That(result, Does.Contain("graph TD"));
}
[Test]
public void GenerateMarkdown_WithLogicalExpression_IncludesLogic()
{
// Arrange
var expr1 = new NumberLiteralExpression(5) > new NumberLiteralExpression(3);
var expr2 = new NumberLiteralExpression(10) < new NumberLiteralExpression(20);
var expression = new AndExpression(expr1, expr2);
// Act
var result = _generator.GenerateMarkdown(expression);
// Assert
Assert.That(result, Does.Contain("AND"));
Assert.That(result, Does.Contain("mermaid"));
}
[Test]
public void GenerateMarkdown_WithTitle_IncludesTitle()
{
// Arrange
var expression = new StringLiteralExpression("test");
// Act
var result = _generator.GenerateMarkdown(expression, "Test Expression");
// Assert
Assert.That(result, Does.StartWith("# Test Expression"));
}
[Test]
public void GenerateMarkdown_ComplexExpression_GeneratesCompleteDoc()
{
// Arrange
Expression quantity = new NumberLiteralExpression(10);
Expression price = new NumberLiteralExpression(25.50m);
Expression discount = new NumberLiteralExpression(0.15m);
var expression = quantity * price * (1 - discount);
// Act
var result = _generator.GenerateMarkdown(expression, "Order Total");
// Assert
Assert.That(result, Does.Contain("# Order Total"));
Assert.That(result, Does.Contain("## Expression Structure"));
Assert.That(result, Does.Contain("## Expression Type"));
Assert.That(result, Does.Contain("## Mermaid Diagram"));
Assert.That(result, Does.Contain("## Mathematical Expression"));
Assert.That(result, Does.Contain("Arithmetic"));
Assert.That(result.Length, Is.GreaterThan(200));
}
[Test]
public void GenerateMathematicalExpression_WithArithmetic_GeneratesLatex()
{
// Arrange
Expression a = new NumberLiteralExpression(5);
Expression b = new NumberLiteralExpression(3);
var expression = a + b;
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
// Assert
Assert.That(result, Does.Contain("$$"));
Assert.That(result, Does.Contain("+"));
Assert.That(result, Does.Contain("5"));
Assert.That(result, Does.Contain("3"));
}
[Test]
public void GenerateMathematicalExpression_WithMultiplication_UsesTimesSymbol()
{
// Arrange
Expression x = new NumberLiteralExpression(10);
Expression y = new NumberLiteralExpression(20);
var expression = x * y;
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
// Assert
Assert.That(result, Does.Contain("\\times"));
}
[Test]
public void GenerateMathematicalExpression_WithComparison_UsesCorrectSymbol()
{
// Arrange
Expression a = new NumberLiteralExpression(10);
Expression b = new NumberLiteralExpression(20);
var expression = a >= b;
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
// Assert
Assert.That(result, Does.Contain("\\geq"));
}
[Test]
public void GenerateMathematicalExpression_WithLogicalAnd_UsesLandSymbol()
{
// Arrange
var expr1 = new NumberLiteralExpression(5) > new NumberLiteralExpression(3);
var expr2 = new NumberLiteralExpression(10) < new NumberLiteralExpression(20);
var expression = new AndExpression(expr1, expr2);
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
// Assert
Assert.That(result, Does.Contain("\\land"));
}
[Test]
public void GenerateMathematicalExpression_Inline_UsesSingleDollar()
{
// Arrange
var expression = new NumberLiteralExpression(42);
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression, inline: true);
// Assert
Assert.That(result, Does.StartWith("$"));
Assert.That(result, Does.EndWith("$"));
Assert.That(result, Does.Not.Contain("$$"));
}
[Test]
public void GenerateMathematicalExpression_Block_UsesDoubleDollar()
{
// Arrange
var expression = new NumberLiteralExpression(42);
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression, inline: false);
// Assert
Assert.That(result, Does.Contain("$$"));
}
[Test]
public void GenerateMathematicalExpression_ComplexArithmetic_GeneratesCorrectLatex()
{
// Arrange
Expression quantity = new NumberLiteralExpression(10);
Expression price = new NumberLiteralExpression(25);
Expression discount = new NumberLiteralExpression(0.1m);
var expression = quantity * price * (1 - discount);
// Act
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
// Assert
Assert.That(result, Does.Contain("\\times"));
Assert.That(result, Does.Contain("10"));
Assert.That(result, Does.Contain("25"));
Assert.That(result, Does.Contain("0.1"));
}
[Test]
public void GenerateRawMathematicalExpression_CauchySchwarzInequality_WithDollarFormat()
{
// Arrange
var latex = @"\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)";
// Act
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, format: "dollar", inline: false);
// Assert
Assert.That(result, Does.StartWith("$$"));
Assert.That(result, Does.EndWith("$$"));
Assert.That(result, Does.Contain("\\sum_{k=1}^n"));
Assert.That(result, Does.Contain("a_k b_k"));
Assert.That(result, Does.Contain("\\leq"));
}
[Test]
public void GenerateRawMathematicalExpression_CauchySchwarzInequality_WithMathFormat()
{
// Arrange
var latex = @"\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)";
// Act
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, format: "math");
// Assert
Assert.That(result, Does.StartWith("```math"));
Assert.That(result, Does.EndWith("```"));
Assert.That(result, Does.Contain("\\sum_{k=1}^n"));
Assert.That(result, Does.Contain("a_k b_k"));
Assert.That(result, Does.Contain("\\leq"));
}
[Test]
public void GenerateRawMathematicalExpression_Inline_UsesSingleDollar()
{
// Arrange
var latex = "E = mc^2";
// Act
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, inline: true);
// Assert
Assert.That(result, Does.StartWith("$"));
Assert.That(result, Does.EndWith("$"));
Assert.That(result, Does.Not.Contain("```"));
Assert.That(result, Is.EqualTo("$E = mc^2$"));
}
}