Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 10, 2023
1 parent 9743b48 commit 9c3b694
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2023 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.bme.mit.theta.analysis.algorithm;

import hu.bme.mit.theta.analysis.Action;
import hu.bme.mit.theta.analysis.State;
import hu.bme.mit.theta.analysis.stubs.ActionStub;
import hu.bme.mit.theta.analysis.stubs.PartialOrdStub;
import hu.bme.mit.theta.analysis.stubs.StateStub;
import org.junit.Assert;
import org.junit.Test;

public class ArgStructuralEqualityTest {

private static ARG<State, Action> createArg(boolean variant) {
ARG<State, Action> arg = ARG.create(new PartialOrdStub());
Action act = new ActionStub("A");

ArgNode<State, Action> s0 = arg.createInitNode(new StateStub("s0"), false);
ArgNode<State, Action> s10 = arg.createSuccNode(s0, act, new StateStub("s10"),
false);
ArgNode<State, Action> s20 = arg.createSuccNode(s10, act, new StateStub("s20"),
true);
ArgNode<State, Action> s21 = arg.createSuccNode(s10, act, new StateStub("s21"),
false);
ArgNode<State, Action> s11 = arg.createSuccNode(s0, act, new StateStub("s11"),
true);
if(variant) {
ArgNode<State, Action> s12a = arg.createSuccNode(s0, act, new StateStub("s12a"),
false);
} else {
ArgNode<State, Action> s12b = arg.createSuccNode(s0, act, new StateStub("s12b"),
false);
}
return arg;
}

@Test
public void testARGEquals() {
var arg1 = createArg(true);
var arg2 = createArg(true);
var arg3 = createArg(false);

Assert.assertNotEquals("Reference-based equality", arg1, arg2);
Assert.assertTrue("Structural equality (true)", ArgStructuralEquality.equals(arg1, arg2));
Assert.assertFalse("Structural equality (false)", ArgStructuralEquality.equals(arg1, arg3));
}

@Test
public void testARGHashCode() {
var arg1 = createArg(true);
var arg2 = createArg(true);
var arg3 = createArg(false);

Assert.assertNotEquals("Reference-based hashcode", arg1.hashCode(), arg2.hashCode());
Assert.assertEquals("Structural hashcode (true)", ArgStructuralEquality.hashCode(arg1), ArgStructuralEquality.hashCode(arg2));
Assert.assertNotEquals("Structural hashcode (false)", ArgStructuralEquality.hashCode(arg1), ArgStructuralEquality.hashCode(arg3));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import hu.bme.mit.theta.analysis.Action;

import java.util.Objects;

public class ActionStub implements Action {

private final String label;
Expand All @@ -29,4 +31,17 @@ public ActionStub(final String label) {
public String toString() {
return label;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ActionStub that = (ActionStub) o;
return Objects.equals(label, that.label);
}

@Override
public int hashCode() {
return Objects.hash(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import hu.bme.mit.theta.analysis.State;

import java.util.Objects;

public class StateStub implements State {

private final String label;
Expand All @@ -35,4 +37,16 @@ public String toString() {
return label;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StateStub stateStub = (StateStub) o;
return Objects.equals(label, stateStub.label);
}

@Override
public int hashCode() {
return Objects.hash(label);
}
}

0 comments on commit 9c3b694

Please sign in to comment.