Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a lil bit elegancy RS Flip-Flop logic, and some bad tests.

  • Loading branch information...
commit e2a2e6fb6a2c0d7e0c660c3f3115cc90aee51d8a 1 parent 0d2e78d
@Procurares authored
View
5 Latches/nbproject/private/retriever/catalog.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
+ <system systemId="http://www.w3.org/2000/svg" uri="www.w3.org/2000/svg.xml"/>
+ <system systemId="http://www.w3.org/1999/xlink" uri="www.w3.org/1999/xlink"/>
+</catalog>
View
32 Latches/nbproject/private/retriever/www.w3.org/1999/xlink
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html lang="en">
+<head>
+ <title>XLink namespace</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <link rel="stylesheet" type="text/css"
+ href="http://www.w3.org/StyleSheets/TR/base.css">
+</head>
+<body>
+<div class="head">
+<p><a href="http://www.w3.org/"><img class="head"
+src="http://www.w3.org/Icons/WWW/w3c_home.gif" alt="W3C"></a></p>
+</div>
+<p>
+This is an XML namespace defined in the
+<a href="http://www.w3.org/TR/xlink/">XML Linking Language (XLink) specification</a>.
+</p>
+<p>
+For more information about XML, please refer to <a
+href="http://www.w3.org/TR/REC-xml">The Extensible Markup Language
+(XML) 1.0 specification</a>. For more information about XML
+namespaces, please refer to the
+<a href="http://www.w3.org/TR/REC-xml-names">Namespaces in XML
+specification</a>.
+
+<hr>
+<address>
+ <a href="/Help/Webmaster">Webmaster</a><BR>
+ Last modified: $Date: 2000/06/22 15:15:22 $
+</address>
+</body>
+</html>
View
0  ...s/nbproject/private/retriever/www.w3.org/2000/svg → ...project/private/retriever/www.w3.org/2000/svg.xml
File renamed without changes
View
30 Latches/src/net/unikernel/bummel/latches/RS/RS.java
@@ -13,8 +13,8 @@
@Element.ElementData(dataFile="element_info.xml")
public class RS extends BasicElement
{
+ private int state;
private String R, S, Q, notQ;
- private boolean SChecked = false, RChecked = false;
public RS()
{
super(new String[]{"reset", "set", "q", "notq"});
@@ -22,6 +22,7 @@ public RS()
S = getPorts().get(1);
Q = getPorts().get(2);
notQ = getPorts().get(3);
+ state = 1;
}
@Override
public Map<String, Double> process(Map<String, Double> valuesOnPorts)
@@ -31,8 +32,7 @@ public RS()
{
valuesOnPorts.put(Q, 1.);
valuesOnPorts.put(notQ, 0.);
- SChecked = true;
- RChecked = false;
+ state = 2;
}
else
if(valuesOnPorts.get(R).compareTo(new Double(0)) != 0 &&
@@ -40,27 +40,25 @@ public RS()
{
valuesOnPorts.put(Q, 0.);
valuesOnPorts.put(notQ, 1.);
- SChecked = false;
- RChecked = true;
+ state = 3;
}
else
if(valuesOnPorts.get(R).compareTo(new Double(0)) == 0 &&
valuesOnPorts.get(S).compareTo(new Double(0)) == 0)
{
- if(SChecked)
+ switch(state)
{
- valuesOnPorts.put(Q, 1.);
- }
- else
- if(RChecked)
- {
- valuesOnPorts.put(notQ, 1.);
- }
- else
- {
+ case 1:
valuesOnPorts.put(Q, 0.);
valuesOnPorts.put(notQ, 0.);
- }
+ break;
+ case 2:
+ valuesOnPorts.put(Q, 1.);
+ break;
+ case 3:
+ valuesOnPorts.put(notQ, 1.);
+ break;
+ }
}
else
if(valuesOnPorts.get(R).compareTo(new Double(0)) != 0 &&
View
144 Latches/test/unit/src/net/unikernel/bummel/latches/RSTest.java
@@ -0,0 +1,144 @@
+package net.unikernel.bummel.latches;
+
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.*;
+import static org.junit.Assert.*;
+import net.unikernel.bummel.latches.RS.RS;
+
+/**
+ *
+ * @author Roma
+ */
+public class RSTest
+{
+ RS instance;
+ public RSTest()
+ {
+ instance = new RS();
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception
+ {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception
+ {
+ }
+ @Before
+ public void setUp()
+ {
+ }
+
+ @After
+ public void tearDown()
+ {
+ }
+ @Test
+ public void A()
+ {
+ System.out.println("A");
+ Map<String, Double> valuesOnPorts = new TreeMap<>();
+ valuesOnPorts.put("reset",0.);
+ valuesOnPorts.put("set",1.);
+ valuesOnPorts.put("q",0.);
+ valuesOnPorts.put("notq",0.);
+ Map<String, Double> expResult= new TreeMap<>();
+ expResult.put("reset", 0.);
+ expResult.put("set", 0.);
+ expResult.put("q", 1.);
+ expResult.put("notq", 0.);
+ Map result = instance.process(valuesOnPorts);
+ assertEquals(expResult, result);
+ System.out.println("Q: " + result.get("q"));
+ System.out.println("NotQ: " + result.get("notq"));
+ System.out.println("-------------------------");
+ }
+ @Test
+ public void B()
+ {
+ System.out.println("B");
+ Map<String, Double> valuesOnPorts = new TreeMap<>();
+ valuesOnPorts.put("reset",0.);
+ valuesOnPorts.put("set",0.);
+ valuesOnPorts.put("q",0.);
+ valuesOnPorts.put("notq",0.);
+ Map<String, Double> expResult= new TreeMap<>();
+ expResult.put("reset", 0.);
+ expResult.put("set", 0.);
+ expResult.put("q", 0.);
+ expResult.put("notq", 1.);
+ Map result = instance.process(valuesOnPorts);
+ assertEquals(expResult, result);
+ System.out.println("Q: " + result.get("q"));
+ System.out.println("NotQ: " + result.get("notq"));
+ System.out.println("-------------------------");
+ }
+ @Test
+ public void C()
+ {
+ System.out.println("C");
+ Map<String, Double> valuesOnPorts = new TreeMap<>();
+ valuesOnPorts.put("reset",1.);
+ valuesOnPorts.put("set",0.);
+ valuesOnPorts.put("q",0.);
+ valuesOnPorts.put("notq",0.);
+ Map<String, Double> expResult= new TreeMap<>();
+ expResult.put("reset", 0.);
+ expResult.put("set", 0.);
+ expResult.put("q", 0.);
+ expResult.put("notq", 1.);
+ Map result = instance.process(valuesOnPorts);
+ assertEquals(expResult, result);
+ System.out.println("Q: " + result.get("q"));
+ System.out.println("NotQ: " + result.get("notq"));
+ System.out.println("-------------------------");
+ }
+ @Test
+ public void D()
+ {
+ System.out.println("D");
+ Map<String, Double> valuesOnPorts = new TreeMap<>();
+ valuesOnPorts.put("reset",0.);
+ valuesOnPorts.put("set",1.);
+ valuesOnPorts.put("q",0.);
+ valuesOnPorts.put("notq",0.);
+ Map<String, Double> expResult= new TreeMap<>();
+ expResult.put("reset", 0.);
+ expResult.put("set", 0.);
+ expResult.put("q", 1.);
+ expResult.put("notq", 0.);
+ Map result = instance.process(valuesOnPorts);
+ assertEquals(expResult, result);
+ System.out.println("Q: " + result.get("q"));
+ System.out.println("NotQ: " + result.get("notq"));
+ System.out.println("-------------------------");
+ }
+ @Test
+ public void E()
+ {
+ System.out.println("E");
+ Map<String, Double> valuesOnPorts = new TreeMap<>();
+ valuesOnPorts.put("reset",1.);
+ valuesOnPorts.put("set",0.);
+ valuesOnPorts.put("q",0.);
+ valuesOnPorts.put("notq",0.);
+ Map<String, Double> expResult= new TreeMap<>();
+ expResult.put("reset", 0.);
+ expResult.put("set", 0.);
+ expResult.put("q", 0.);
+ expResult.put("notq", 1.);
+ Map result = instance.process(valuesOnPorts);
+ assertEquals(expResult, result);
+ System.out.println("Q: " + result.get("q"));
+ System.out.println("NotQ: " + result.get("notq"));
+ System.out.println("-------------------------");
+ }
+ // TODO add test methods here.
+ // The methods must be annotated with annotation @Test. For example:
+ //
+ // @Test
+ // public void hello() {}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.