Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@

.DS_Store

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

# Ignore config folder.
.idea


11 changes: 0 additions & 11 deletions MathParser/MathParser.iml

This file was deleted.

27 changes: 27 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.4.2/userguide/building_java_projects.html
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13.2'
}

application {
// Define the main class for the application.
mainClass = 'MathParser.App'
}
44 changes: 44 additions & 0 deletions app/src/test/java/com/aghajari/MathParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.aghajari;

import com.aghajari.math.MathParser;
import org.junit.Test;

/**
* test code from README.md
*/
public class MathParserTest {
@Test
public void test(){
MathParser parser = MathParser.create();
try {
System.out.println(parser.parse("2 + 2")); // 4.0
System.out.println(parser.parse("5^2 * (2 + 3 * 4) + 5!/4")); // 380.0

parser.addExpression("f(x, y) = 2(x + y)"); // addFunction
parser.addExpression("x0 = 1 + 2 ^ 2"); // addVariable
parser.addExpression("y0 = 2x0"); // addVariable
System.out.println(parser.parse("1 + 2f(x0, y0)/3")); // 21.0

System.out.println(parser.parse("sin(3pi/2) + tan(45°)"));

System.out.println(parser.parse("2 ∫(x, (x^3)/(x+1), 5, 10)")); // 517.121062
System.out.println(parser.parse("derivative(x, x^3, 2)")); // 12.0
System.out.println(parser.parse("lim(x->2, x^(x + 2)) / 2")); // 8.0
System.out.println(parser.parse("Σ(i, 2i^2, 1, 5)")); // 220.0

System.out.println(parser.parse("5!/4")); // 30.0
System.out.println(parser.parse("(0b100)!")); // 4! = 24.0
System.out.println(parser.parse("log2((0xFF) + 1)")); // log2(256) = 8.0
System.out.println(parser.parse("(0o777)")); // 511.0

System.out.println(parser.parse("2 + if(2^5 >= 5!, 1, 0)")); // 2.0

parser.addExpression("gcd(x, y) = if(y = 0, x, gcd(y, x % y))"); // GCD Recursive
System.out.println(parser.parse("gcd(8, 20)")); // 4.0

System.out.println(parser.parse("gcd(8, 20, 100, 150)")); // 2.0
} catch (Exception e){
e.printStackTrace();
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
234 changes: 234 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading