Commits

Brett Giles committed 2753de3

Changed export of classical values to same XML regardless of if in Qstack or is the Cstack.

Comments (0)

Files changed (2)

Emulator/src/QServer/StackToXML.lhs

     toXML (Right b) = surroundWith "cbool" $ show b
 
   instance XML ClassicalStack where
-    toXML a = listToXML "Cstack"  $ Stack.toList a
-    boundedToXML n  a = listToXML "Cstack"  $ take n $ Stack.toList a
+    toXML a = listToXML "Classical"  $ Stack.toList a
+    boundedToXML n  a = listToXML "Classical"  $ take n $ Stack.toList a
 
   instance (XML b) => XML (StackDescriptor b) where
     toXML StackZero = "<Zero/>"
     toXML (StackValue b) = surroundWith "Value" $ toXML b
-    toXML (StackClassical cs) = listToXML "ClassicalStack" cs
+    toXML (StackClassical cs) = listToXML "Classical" cs
     toXML (StackQubit b) = listToXML "Qubits" b
     toXML (StackData constructors) =
       surroundWith "AlgebraicData" $ sdXML constructors

Emulator/src/Spec/QServer/StackToXMLSpec.lhs

     import Test.QuickCheck hiding (property)
     import Test.HUnit
 
+    import Data.Stack
 
     import Spec.SpecHelper
 
     import QSM.BasicData
 
     import Data.LazyNum
+    import QSM.Components.ClassicalStack
     import QSM.QuantumStack.QSDefinition
     import QServer.StackToXML
 
+
     instance Quantum LazyNum
 
     main = hspecX tests
 
     xmlValues =  [(StackZero, "<Zero/>"),
                   (StackValue (SZero), "<Value><number>0</number></Value>" )]
+    cstacks :: [(ClassicalStack,String)]
+    cstacks = [(Stack [Left 5, Right False, Left (-1)], "<Classical><cint>5</cint><cbool>False</cbool><cint>-1</cint></Classical>")]
 
     stackXML = [ (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackQubit [(Z,Z)]),
       "<Qstack><int>1</int><bool>True</bool><substacks><Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>"),
           "<Qstack><int>-1</int><bool>False</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++ -- OnDiag False takes just what it sees.
           "<Qstack><int>-1</int><bool>False</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++
           "</substacks>"++
-          "<Qubits><pair><qz/><qz/></pair><pair><qz/><qo/></pair><pair><qo/><qo/></pair></Qubits></Qstack>")]
+          "<Qubits><pair><qz/><qz/></pair><pair><qz/><qo/></pair><pair><qo/><qo/></pair></Qubits></Qstack>"),
+          (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5)),QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackClassical [Left 4, Right True]),
+            "<Qstack><int>1</int><bool>True</bool><substacks>"++
+            "<Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++
+            "<Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack></substacks>"++
+            "<Classical><cint>4</cint><cbool>True</cbool></Classical></Qstack>")]
 
 
     stackBoundedXML = [ (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackQubit [(Z,Z)]), "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>")]
 
     tests =  describe "StackToXML" $ do
       mapM_ (uncurry checkIt) xmlValues
+      mapM_ (uncurry checkIt) cstacks
       context "unbounded qstack" $ mapM_ (uncurry checkUnbounded) stackXML
       context "bounded qstack" $ mapM_ (uncurry checkBounded) stackBoundedXML