1 /* 2 * @file TestAssignmentRule.java 3 * @brief AssignmentRule unit tests 4 * 5 * @author Akiya Jouraku (Java conversion) 6 * @author Ben Bornstein 7 * 8 * ====== WARNING ===== WARNING ===== WARNING ===== WARNING ===== WARNING ====== 9 * 10 * DO NOT EDIT THIS FILE. 11 * 12 * This file was generated automatically by converting the file located at 13 * src/sbml/test/TestAssignmentRule.c 14 * using the conversion program dev/utilities/translateTests/translateTests.pl. 15 * Any changes made here will be lost the next time the file is regenerated. 16 * 17 * ----------------------------------------------------------------------------- 18 * This file is part of libSBML. Please visit http://sbml.org for more 19 * information about SBML, and the latest version of libSBML. 20 * 21 * Copyright (C) 2020 jointly by the following organizations: 22 * 1. California Institute of Technology, Pasadena, CA, USA 23 * 2. University of Heidelberg, Heidelberg, Germany 24 * 3. University College London, London, UK 25 * 26 * Copyright 2005-2010 California Institute of Technology. 27 * Copyright 2002-2005 California Institute of Technology and 28 * Japan Science and Technology Corporation. 29 * 30 * This library is free software; you can redistribute it and/or modify it 31 * under the terms of the GNU Lesser General Public License as published by 32 * the Free Software Foundation. A copy of the license agreement is provided 33 * in the file named "LICENSE.txt" included with this software distribution 34 * and also available online as http://sbml.org/software/libsbml/license.html 35 * ----------------------------------------------------------------------------- 36 */ 37 38 package org.sbml.libsbml.test.sbml; 39 40 import org.sbml.libsbml.*; 41 42 import java.io.File; 43 import java.lang.AssertionError; 44 45 public class TestAssignmentRule { 46 assertTrue(boolean condition)47 static void assertTrue(boolean condition) throws AssertionError 48 { 49 if (condition == true) 50 { 51 return; 52 } 53 throw new AssertionError(); 54 } 55 assertEquals(Object a, Object b)56 static void assertEquals(Object a, Object b) throws AssertionError 57 { 58 if ( (a == null) && (b == null) ) 59 { 60 return; 61 } 62 else if ( (a == null) || (b == null) ) 63 { 64 throw new AssertionError(); 65 } 66 else if (a.equals(b)) 67 { 68 return; 69 } 70 71 throw new AssertionError(); 72 } 73 assertNotEquals(Object a, Object b)74 static void assertNotEquals(Object a, Object b) throws AssertionError 75 { 76 if ( (a == null) && (b == null) ) 77 { 78 throw new AssertionError(); 79 } 80 else if ( (a == null) || (b == null) ) 81 { 82 return; 83 } 84 else if (a.equals(b)) 85 { 86 throw new AssertionError(); 87 } 88 } 89 assertEquals(boolean a, boolean b)90 static void assertEquals(boolean a, boolean b) throws AssertionError 91 { 92 if ( a == b ) 93 { 94 return; 95 } 96 throw new AssertionError(); 97 } 98 assertNotEquals(boolean a, boolean b)99 static void assertNotEquals(boolean a, boolean b) throws AssertionError 100 { 101 if ( a != b ) 102 { 103 return; 104 } 105 throw new AssertionError(); 106 } 107 assertEquals(int a, int b)108 static void assertEquals(int a, int b) throws AssertionError 109 { 110 if ( a == b ) 111 { 112 return; 113 } 114 throw new AssertionError(); 115 } 116 assertNotEquals(int a, int b)117 static void assertNotEquals(int a, int b) throws AssertionError 118 { 119 if ( a != b ) 120 { 121 return; 122 } 123 throw new AssertionError(); 124 } 125 private Rule AR; 126 setUp()127 protected void setUp() throws Exception 128 { 129 AR = new AssignmentRule(2,4); 130 if (AR == null); 131 { 132 } 133 } 134 tearDown()135 protected void tearDown() throws Exception 136 { 137 AR = null; 138 } 139 test_AssignmentRule_L2_create()140 public void test_AssignmentRule_L2_create() 141 { 142 assertTrue( AR.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE ); 143 assertTrue( AR.getMetaId().equals("") == true ); 144 assertTrue( AR.getNotes() == null ); 145 assertTrue( AR.getAnnotation() == null ); 146 assertTrue( AR.getFormula().equals("") == true ); 147 assertTrue( AR.getMath() == null ); 148 assertTrue( AR.getVariable().equals("") == true ); 149 assertTrue( AR.getType() == libsbml.RULE_TYPE_SCALAR ); 150 } 151 test_AssignmentRule_createWithFormula()152 public void test_AssignmentRule_createWithFormula() 153 { 154 ASTNode math; 155 String formula; 156 Rule ar = new AssignmentRule(2,4); 157 ar.setVariable( "s"); 158 ar.setFormula( "1 + 1"); 159 assertTrue( ar.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE ); 160 assertTrue( ar.getMetaId().equals("") == true ); 161 assertTrue(ar.getVariable().equals( "s")); 162 math = ar.getMath(); 163 assertTrue( math != null ); 164 formula = libsbml.formulaToString(math); 165 assertTrue( formula != null ); 166 assertTrue(formula.equals( "1 + 1")); 167 assertTrue(ar.getFormula().equals(formula)); 168 ar = null; 169 } 170 test_AssignmentRule_createWithMath()171 public void test_AssignmentRule_createWithMath() 172 { 173 ASTNode math = libsbml.parseFormula("1 + 1"); 174 Rule ar = new AssignmentRule(2,4); 175 ar.setVariable( "s"); 176 ar.setMath(math); 177 assertTrue( ar.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE ); 178 assertTrue( ar.getMetaId().equals("") == true ); 179 assertTrue(ar.getVariable().equals( "s")); 180 assertTrue(ar.getFormula().equals( "1 + 1")); 181 assertTrue( !ar.getMath().equals(math) ); 182 ar = null; 183 } 184 test_AssignmentRule_createWithNS()185 public void test_AssignmentRule_createWithNS() 186 { 187 XMLNamespaces xmlns = new XMLNamespaces(); 188 xmlns.add( "http://www.sbml.org", "testsbml"); 189 SBMLNamespaces sbmlns = new SBMLNamespaces(2,1); 190 sbmlns.addNamespaces(xmlns); 191 Rule object = new AssignmentRule(sbmlns); 192 assertTrue( object.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE ); 193 assertTrue( object.getMetaId().equals("") == true ); 194 assertTrue( object.getNotes() == null ); 195 assertTrue( object.getAnnotation() == null ); 196 assertTrue( object.getLevel() == 2 ); 197 assertTrue( object.getVersion() == 1 ); 198 assertTrue( object.getNamespaces() != null ); 199 assertTrue( object.getNamespaces().getLength() == 2 ); 200 object = null; 201 } 202 test_AssignmentRule_free_NULL()203 public void test_AssignmentRule_free_NULL() 204 { 205 } 206 test_AssignmentRule_setVariable()207 public void test_AssignmentRule_setVariable() 208 { 209 String variable = "x"; 210 AR.setVariable(variable); 211 assertTrue(AR.getVariable().equals(variable)); 212 assertEquals( true, AR.isSetVariable() ); 213 if (AR.getVariable() == variable); 214 { 215 } 216 AR.setVariable(AR.getVariable()); 217 assertTrue(AR.getVariable().equals(variable)); 218 AR.setVariable(""); 219 assertEquals( false, AR.isSetVariable() ); 220 if (AR.getVariable() != null); 221 { 222 } 223 } 224 225 /** 226 * Loads the SWIG-generated libSBML Java module when this class is 227 * loaded, or reports a sensible diagnostic message about why it failed. 228 */ 229 static 230 { 231 String varname; 232 String shlibname; 233 234 if (System.getProperty("mrj.version") != null) 235 { 236 varname = "DYLD_LIBRARY_PATH"; // We're on a Mac. 237 shlibname = "libsbmlj.jnilib and/or libsbml.dylib"; 238 } 239 else 240 { 241 varname = "LD_LIBRARY_PATH"; // We're not on a Mac. 242 shlibname = "libsbmlj.so and/or libsbml.so"; 243 } 244 245 try 246 { 247 System.loadLibrary("sbmlj"); 248 // For extra safety, check that the jar file is in the classpath. 249 Class.forName("org.sbml.libsbml.libsbml"); 250 } 251 catch (SecurityException e) 252 { 253 e.printStackTrace(); 254 System.err.println("Could not load the libSBML library files due to a"+ 255 " security exception.\n"); 256 System.exit(1); 257 } 258 catch (UnsatisfiedLinkError e) 259 { 260 e.printStackTrace(); 261 System.err.println("Error: could not link with the libSBML library files."+ 262 " It is likely\nyour " + varname + 263 " environment variable does not include the directories\n"+ 264 "containing the " + shlibname + " library files.\n"); 265 System.exit(1); 266 } 267 catch (ClassNotFoundException e) 268 { 269 e.printStackTrace(); 270 System.err.println("Error: unable to load the file libsbmlj.jar."+ 271 " It is likely\nyour -classpath option and CLASSPATH" + 272 " environment variable\n"+ 273 "do not include the path to libsbmlj.jar.\n"); 274 System.exit(1); 275 } 276 } 277 } 278 279