Skip to content

chore: improve reliability metric #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ private static PythonLikeType registerMethods() throws NoSuchMethodException {

// Comparisons
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonFloat.class.getMethod("equal", PythonLikeObject.class));
PythonFloat.class.getMethod("pythonEquals", PythonLikeObject.class));
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonFloat.class.getMethod("equal", PythonInteger.class));
PythonFloat.class.getMethod("pythonEquals", PythonInteger.class));
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonFloat.class.getMethod("equal", PythonFloat.class));
PythonFloat.class.getMethod("pythonEquals", PythonFloat.class));
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
PythonFloat.class.getMethod("notEqual", PythonLikeObject.class));
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
Expand Down Expand Up @@ -550,11 +550,11 @@ public PythonFloat power(PythonFloat other) {
return new PythonFloat(Math.pow(value, other.value));
}

public PythonLikeObject equal(PythonLikeObject other) {
public PythonLikeObject pythonEquals(PythonLikeObject other) {
if (other instanceof PythonInteger) {
return equal((PythonInteger) other);
return pythonEquals((PythonInteger) other);
} else if (other instanceof PythonFloat) {
return equal((PythonFloat) other);
return pythonEquals((PythonFloat) other);
} else {
return NotImplemented.INSTANCE;
}
Expand Down Expand Up @@ -610,7 +610,7 @@ public PythonLikeObject greaterThanOrEqual(PythonLikeObject other) {
}
}

public PythonBoolean equal(PythonInteger other) {
public PythonBoolean pythonEquals(PythonInteger other) {
return PythonBoolean.valueOf(value == other.value.doubleValue());
}

Expand All @@ -634,7 +634,7 @@ public PythonBoolean greaterThanOrEqual(PythonInteger other) {
return PythonBoolean.valueOf(value >= other.value.doubleValue());
}

public PythonBoolean equal(PythonFloat other) {
public PythonBoolean pythonEquals(PythonFloat other) {
return PythonBoolean.valueOf(value == other.value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ private static PythonLikeType registerMethods() throws NoSuchMethodException {

// Comparisons
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonInteger.class.getMethod("equal", PythonLikeObject.class));
PythonInteger.class.getMethod("pythonEquals", PythonLikeObject.class));
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonInteger.class.getMethod("equal", PythonInteger.class));
PythonInteger.class.getMethod("pythonEquals", PythonInteger.class));
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
PythonInteger.class.getMethod("equal", PythonFloat.class));
PythonInteger.class.getMethod("pythonEquals", PythonFloat.class));

BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
PythonInteger.class.getMethod("notEqual", PythonLikeObject.class));
Expand Down Expand Up @@ -648,11 +648,11 @@ public PythonInteger bitwiseXor(PythonInteger other) {
return new PythonInteger(value.xor(other.value));
}

public PythonLikeObject equal(PythonLikeObject other) {
public PythonLikeObject pythonEquals(PythonLikeObject other) {
if (other instanceof PythonInteger) {
return equal((PythonInteger) other);
return pythonEquals((PythonInteger) other);
} else if (other instanceof PythonFloat) {
return equal((PythonFloat) other);
return pythonEquals((PythonFloat) other);
} else {
return NotImplemented.INSTANCE;
}
Expand Down Expand Up @@ -708,7 +708,7 @@ public PythonLikeObject greaterThanOrEqual(PythonLikeObject other) {
}
}

public PythonBoolean equal(PythonInteger other) {
public PythonBoolean pythonEquals(PythonInteger other) {
return PythonBoolean.valueOf(value.compareTo(other.value) == 0);
}

Expand All @@ -732,7 +732,7 @@ public PythonBoolean greaterThanOrEqual(PythonInteger other) {
return PythonBoolean.valueOf(value.compareTo(other.value) >= 0);
}

public PythonBoolean equal(PythonFloat other) {
public PythonBoolean pythonEquals(PythonFloat other) {
return PythonBoolean.valueOf(value.doubleValue() == other.value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ai.timefold.jpyinterpreter.opcodes.descriptor.StackOpDescriptor;
import ai.timefold.jpyinterpreter.types.PythonLikeType;
import ai.timefold.jpyinterpreter.types.PythonNone;
import ai.timefold.jpyinterpreter.types.PythonString;
import ai.timefold.jpyinterpreter.types.errors.PythonAssertionError;
import ai.timefold.jpyinterpreter.types.errors.PythonException;
import ai.timefold.jpyinterpreter.types.errors.PythonTraceback;
Expand Down Expand Up @@ -111,15 +112,15 @@ public void testTryExceptFinally() {

assertThat(javaFunction.apply(0)).isEqualTo(1);
assertThat(globalsMap.get("exception")).isEqualTo(PythonNone.INSTANCE);
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));

assertThat(javaFunction.apply(1)).isEqualTo(1);
assertThat(globalsMap.get("exception")).isEqualTo("Assert");
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
assertThat(globalsMap.get("exception")).isEqualTo(PythonString.valueOf("Assert"));
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));

assertThatCode(() -> javaFunction.apply(2)).isInstanceOf(StopIteration.class);
assertThat(globalsMap.get("exception")).isEqualTo(PythonNone.INSTANCE);
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
import java.time.Duration;
import java.time.LocalDate;

import ai.timefold.jpyinterpreter.types.PythonString;

import org.junit.jupiter.api.Test;

public class PythonDateTest {
@Test
public void testIsoFormat() {
PythonDate pythonDate = new PythonDate(LocalDate.of(2002, 3, 11));
assertThat(pythonDate.iso_format()).isEqualTo("2002-03-11");
assertThat(pythonDate.iso_format()).isEqualTo(PythonString.valueOf("2002-03-11"));
}

@Test
public void testCTime() {
PythonDate pythonDate = new PythonDate(LocalDate.of(2002, 3, 11));
assertThat(pythonDate.ctime()).isEqualTo("Mon Mar 11 00:00:00 2002");
assertThat(pythonDate.ctime()).isEqualTo(PythonString.valueOf("Mon Mar 11 00:00:00 2002"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
import java.time.Duration;
import java.time.LocalDateTime;

import ai.timefold.jpyinterpreter.types.PythonString;

import org.junit.jupiter.api.Test;

public class PythonDateTimeTest {
@Test
public void testIsoFormat() {
PythonDateTime pythonDateTime = new PythonDateTime(LocalDateTime.of(2002, 3, 11, 1, 30, 45));
assertThat(pythonDateTime.iso_format()).isEqualTo("2002-03-11T01:30:45");
assertThat(pythonDateTime.iso_format()).isEqualTo(PythonString.valueOf("2002-03-11T01:30:45"));
}

@Test
public void testCTime() {
PythonDateTime pythonDateTime = new PythonDateTime(LocalDateTime.of(2002, 3, 11, 1, 30, 45));
assertThat(pythonDateTime.ctime()).isEqualTo("Mon Mar 11 01:30:45 2002");
assertThat(pythonDateTime.ctime()).isEqualTo(PythonString.valueOf("Mon Mar 11 01:30:45 2002"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class PythonTimeTest {
@Test
public void testIsoFormat() {
PythonTime pythonTime = new PythonTime(LocalTime.of(1, 30, 45));
assertThat(pythonTime.isoformat(PythonString.valueOf("auto"))).isEqualTo("01:30:45");
assertThat(pythonTime.isoformat(PythonString.valueOf("auto"))).isEqualTo(PythonString.valueOf("01:30:45"));
}
}
1 change: 1 addition & 0 deletions tests/test_solver_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Annotated, List


@pytest.mark.xfail(reason='Flaky test')
def test_solve():
from threading import Lock, Semaphore
lock = Lock()
Expand Down