Skip to content

Commit bd329b1

Browse files
committed
unit tests
1 parent 96469ec commit bd329b1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/main/java/org/mujoco/MuJoCoModelManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void loadFromFile(File config) {
4040
m = MuJoCoLib.mj_loadXML(config.getAbsolutePath(), null, error,error_sz);
4141
if(m==null)
4242
throw new RuntimeException("Model File Failed to load "+error.getString()+" code "+error_sz);
43-
System.out.println("Humanoid model loaded " + m);
43+
System.out.println("MuJoCo model loaded " + config.getAbsolutePath());
4444
d = MuJoCoLib.mj_makeData(m);
4545
setModel(new mjModel_(m));
4646
setData(new mjData_(d));
@@ -78,7 +78,10 @@ public mjData_ getData() {
7878
public void setData(mjData_ daccessable) {
7979
this.daccessable = daccessable;
8080
}
81-
81+
public void step() {
82+
stepOne();
83+
stepTwo();
84+
}
8285
public void stepOne() {
8386
MuJoCoLib.mj_step1(m, d);
8487
}

src/test/java/mujoco/java/MuJoColibTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,29 @@
1515
import org.mujoco.MuJoCoLib.mjModel;
1616
import org.mujoco.MuJoCoLib.mjModel_;
1717
import org.mujoco.MuJoCoLib.mjVFS;
18+
import org.mujoco.MuJoCoModelManager;
1819

1920
public class MuJoColibTest {
21+
@Test
22+
public void managerTest() throws InterruptedException {
23+
String filename = "model/humanoid/humanoid.xml";
24+
File file = new File(filename);
25+
if(!file.exists()) {
26+
fail("File is missing from the disk");
27+
}
28+
MuJoCoModelManager m = new MuJoCoModelManager(file);
29+
mjModel_ model = m.getModel();
30+
mjData_ data = m.getData();
31+
System.out.println("Run model for 10 seconds");
32+
while (data.time() < 10) {
33+
m.stepOne();
34+
//apply controls
35+
m.stepTwo();
36+
// sleep
37+
Thread.sleep(1);
38+
}
39+
m.close();
40+
}
2041
@Test
2142
public void mujocoJNILoadTest() {
2243
System.out.println(System.getProperty("org.bytedeco.javacpp.logger.debug"));

0 commit comments

Comments
 (0)