<commit_before>#include <stdio.h>
#include <string.h>
#include "minunit.h"
 
char *amath_asciimath_to_mathml(char *text, size_t len);
int tests_run = 0;

static char * test_subscripts() {
	char *expr = "x^2+y_1+z_12^34";
	char *against = "<msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msub><mi>y</mi><mn>1</mn></msub><mo>+</mo><msubsup><mi>z</mi><mn>12</mn><mn>34</mn></msubsup>";
	mu_assert("FAILED: subscripts", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_function() {
	char *expr = "sin^-1(x)";
	char *against = "<msup><mo>sin</mo><mn>-1</mn></msup><mrow>(<mi>x</mi>)</mrow>";
	mu_assert("FAILED: function", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_deriv() {
	char *expr = "d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h";
	char *against = "<mfrac><mi>d</mi><mi>dx</mi></mfrac><mi>f</mi><mrow>(<mi>x</mi>)</mrow><mo>=</mo><munder><mo>lim</mo><mrow><mi>h</mi><mo>→</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow>(<mi>x</mi><mo>+</mo><mi>h</mi>)</mrow><mo>−</mo><mi>f</mi><mrow>(<mi>x</mi>)</mrow></mrow><mi>h</mi></mfrac>";
	mu_assert("FAILED: deriv", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_taylor() {
	char *expr = "f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n";
	char *against = "<mi>f</mi><mrow>(<mi>x</mi>)</mrow><mo>=</mo><munderover><mo>∑</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>∞</mo></munderover><mfrac><mrow><msup><mi>f</mi><mrow><mrow>(<mi>n</mi>)</mrow></mrow></msup><mrow>(<mi>a</mi>)</mrow></mrow><mrow><mi>n</mi><mo>!</mo></mrow></mfrac><msup><mrow>(<mi>x</mi><mo>−</mo><mi>a</mi>)</mrow><mi>n</mi></msup>";
	mu_assert("FAILED: taylor", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_integral() {
	char *expr = "int_0^1f(x)dx";
	char *against = "<msubsup><mo>∫</mo><mn>0</mn><mn>1</mn></msubsup><mi>f</mi><mrow>(<mi>x</mi>)</mrow><mi>dx</mi>";
	mu_assert("FAILED: integral", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_matrix() {
	char *expr = "[[a,b],[c,d]]((n),(k))";
	char *against = "<mrow><mo>[</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr><mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>]</mo></mrow><mrow><mo>(</mo><mtable><mtr><mtd><mi>n</mi></mtd></mtr><mtr><mtd><mi>k</mi></mtd></mtr></mtable><mo>)</mo></mrow>";
	mu_assert("FAILED: matrix", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_piecewise() {
	char *expr = "x/x={(1,if x!=0),(\"undefined\",if x=0):}";
	char *against = "<mfrac><mi>x</mi><mi>x</mi></mfrac><mo>=</mo><mrow><mo>{</mo><mtable columnalign=\"left\"><mtr><mtd><mn>1</mn></mtd><mtd><mrow><mspace width=\"1ex\"></mspace><mo>if</mo><mspace width=\"1ex\"></mspace></mrow><mi>x</mi><mo>≠</mo><mn>0</mn></mtd></mtr><mtr><mtd><mrow><mtext>undefined</mtext></mrow></mtd><mtd><mrow><mspace width=\"1ex\"></mspace><mo>if</mo><mspace width=\"1ex\"></mspace></mrow><mi>x</mi><mo>=</mo><mn>0</mn></mtd></mtr></mtable></mrow>";
	mu_assert("FAILED: piecewise", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_frac() {<commit_msg>Fix matrix notation in test<commit_after>#include <stdio.h>
#include <string.h>
#include "minunit.h"
 
char *amath_asciimath_to_mathml(char *text, size_t len);
int tests_run = 0;

static char * test_subscripts() {
	char *expr = "x^2+y_1+z_12^34";
	char *against = "<msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msub><mi>y</mi><mn>1</mn></msub><mo>+</mo><msubsup><mi>z</mi><mn>12</mn><mn>34</mn></msubsup>";
	mu_assert("FAILED: subscripts", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_function() {
	char *expr = "sin^-1(x)";
	char *against = "<msup><mo>sin</mo><mn>-1</mn></msup><mrow>(<mi>x</mi>)</mrow>";
	mu_assert("FAILED: function", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_deriv() {
	char *expr = "d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h";
	char *against = "<mfrac><mi>d</mi><mi>dx</mi></mfrac><mi>f</mi><mrow>(<mi>x</mi>)</mrow><mo>=</mo><munder><mo>lim</mo><mrow><mi>h</mi><mo>→</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow>(<mi>x</mi><mo>+</mo><mi>h</mi>)</mrow><mo>−</mo><mi>f</mi><mrow>(<mi>x</mi>)</mrow></mrow><mi>h</mi></mfrac>";
	mu_assert("FAILED: deriv", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_taylor() {
	char *expr = "f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n";
	char *against = "<mi>f</mi><mrow>(<mi>x</mi>)</mrow><mo>=</mo><munderover><mo>∑</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>∞</mo></munderover><mfrac><mrow><msup><mi>f</mi><mrow><mrow>(<mi>n</mi>)</mrow></mrow></msup><mrow>(<mi>a</mi>)</mrow></mrow><mrow><mi>n</mi><mo>!</mo></mrow></mfrac><msup><mrow>(<mi>x</mi><mo>−</mo><mi>a</mi>)</mrow><mi>n</mi></msup>";
	mu_assert("FAILED: taylor", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_integral() {
	char *expr = "int_0^1f(x)dx";
	char *against = "<msubsup><mo>∫</mo><mn>0</mn><mn>1</mn></msubsup><mi>f</mi><mrow>(<mi>x</mi>)</mrow><mi>dx</mi>";
	mu_assert("FAILED: integral", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_matrix() {
	char *expr = "[,[a,b],[c,d]] (,(n),(k))";
	char *against = "<mrow><mo>[</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr><mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>]</mo></mrow><mrow><mo>(</mo><mtable><mtr><mtd><mi>n</mi></mtd></mtr><mtr><mtd><mi>k</mi></mtd></mtr></mtable><mo>)</mo></mrow>";
	mu_assert("FAILED: matrix", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_piecewise() {
	char *expr = "x/x={(1,if x!=0),(\"undefined\",if x=0):}";
	char *against = "<mfrac><mi>x</mi><mi>x</mi></mfrac><mo>=</mo><mrow><mo>{</mo><mtable columnalign=\"left\"><mtr><mtd><mn>1</mn></mtd><mtd><mrow><mspace width=\"1ex\"></mspace><mo>if</mo><mspace width=\"1ex\"></mspace></mrow><mi>x</mi><mo>≠</mo><mn>0</mn></mtd></mtr><mtr><mtd><mrow><mtext>undefined</mtext></mrow></mtd><mtd><mrow><mspace width=\"1ex\"></mspace><mo>if</mo><mspace width=\"1ex\"></mspace></mrow><mi>x</mi><mo>=</mo><mn>0</mn></mtd></mtr></mtable></mrow>";
	mu_assert("FAILED: piecewise", strcmp(against, amath_asciimath_to_mathml(expr, strlen(expr))) == 0);
	return 0;
}

static char * test_frac() {
{'fraction_non_alphanumeric': 0.3236576928861483, 'fraction_numerical': 0.01413746428034291, 'mean_word_length': 7.6139896373057, 'pattern_counts': {'":': 0, '<': 539, '<?xml version=': 0, '>': 541, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5162173', 'n_tokens_mistral': 3129, 'n_tokens_neox': 3058, 'n_words': 293}