Skip to content

Commit

Permalink
Fixed JK Flip Flop tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lellisls committed Jun 25, 2016
1 parent 3e9f5aa commit 1c902f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/graphicelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void GraphicElement::setOutputs( const QVector< QNEPort* > &outputs ) {
}

void GraphicElement::save( QDataStream &ds ) {
COMMENT( "Saving element. Type: " << objectName( ).toStdString( ), 0 );
COMMENT( "Saving element. Type: " << objectName( ).toStdString( ), 4 );
ds << pos( );
ds << rotation( );

Expand Down Expand Up @@ -123,7 +123,7 @@ void GraphicElement::save( QDataStream &ds ) {
ds << port->portName( );
ds << port->portFlags( );
}
COMMENT( "Finished saving element.", 0 );
COMMENT( "Finished saving element.", 4 );
}

void GraphicElement::load( QDataStream &ds, QMap< quint64, QNEPort* > &portMap, double version ) {
Expand Down
19 changes: 10 additions & 9 deletions test/testelements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,19 @@ void TestElements::testJKFlipFlop( ) {
{ { 0, 0, 0, 1, 0, 0, 1, 1, 0 } }, /* Clear and Preset = false */
{ { 1, 1, 0, 0, 1, 1, 0, 1, 0 } }, /* Clk dwn and J = 0 ( must mantain current state )*/
{ { 1, 1, 0, 0, 1, 1, 0, 1, 0 } }, /* Clk dwn and J = 1 ( must mantain current state )*/
{ { 0, 0, 1, 0, 1, 1, 1, 0, 0 } }, /* Clk up J = 0 K = 0 ( must swap Q and ~Q )*/
{ { 0, 0, 1, 0, 1, 1, 0, 1, 1 } }, /* Clk up J = 0 K = 0 ( must swap Q and ~Q )*/
{ { 0, 0, 1, 1, 1, 1, 0, 1, 0 } }, /* Clk up J = 0 K = 1 */
{ { 0, 0, 1, 1, 1, 1, 0, 1, 1 } }, /* Clk up J = 0 K = 1 */
{ { 0, 1, 1, 1, 1, 1, 1, 0, 0 } }, /* Clk up J = 1 K = 1 ( must swap Q and ~Q )*/
{ { 0, 1, 1, 1, 1, 1, 0, 1, 1 } }, /* Clk up J = 1 K = 1 ( must swap Q and ~Q )*/
{ { 0, 1, 1, 0, 1, 1, 1, 0, 0 } }, /* Clk up J = 1 K = 0 */
{ { 0, 1, 1, 0, 1, 1, 1, 0, 1 } }, /* Clk up J = 1 K = 0 */
{ { 0, 1, 1, 1, 1, 1, 0, 1, 0 } }, /* Clk up J = 1 K = 0 */
{ { 0, 1, 1, 1, 1, 1, 1, 0, 1 } }, /* Clk up J = 1 K = 0 */
{ { 0, 0, 1, 1, 1, 1, 0, 1, 0 } }, /* Clk up J = 0 K = 1 */
{ { 0, 0, 1, 1, 1, 1, 0, 1, 1 } }, /* Clk up J = 0 K = 1 */
{ { 0, 0, 1, 0, 1, 1, 0, 1, 0 } }, /* Clk up J = 0 K = 0 */
{ { 0, 0, 1, 0, 1, 1, 1, 0, 1 } }, /* Clk up J = 0 K = 0 */

}
};
elm.updateLogic( );
// std::cout << " Q J C K p c Q" << std::endl;
for( size_t test = 0; test < truthTable.size( ); ++test ) {
sw.at( 0 )->setOn( false );
sw.at( 1 )->setOn( truthTable.at( test ).at( 0 ) );
Expand All @@ -360,14 +361,14 @@ void TestElements::testJKFlipFlop( ) {
elm.updateLogic( );
elm.output( 0 )->setValue( truthTable.at( test ).at( 8 ) );
elm.output( 1 )->setValue( !truthTable.at( test ).at( 8 ) );
/* std::cout << ( int ) elm.output( 0 )->value( ) << " -> "; */
// std::cout << "test " << test << " : " << ( int ) elm.output( 0 )->value( ) << " -> ";
for( int port = 0; port < 5; ++port ) {
sw.at( port )->setOn( truthTable.at( test ).at( port + 1 ) );
sw.at( port )->updateLogic( );
/* std::cout << truthTable.at(test).at( port + 1 ) << " "; */
// std::cout << truthTable.at(test).at( port + 1 ) << " ";
}
elm.updateLogic( );
/* std::cout << "-> " << ( int ) elm.output( 0 )->value( ) << std::endl; */
// std::cout << "-> " << ( int ) elm.output( 0 )->value( ) << " == " << truthTable.at( test ).at( 6 ) << " ?"<< std::endl;

QCOMPARE( ( int ) elm.output( 0 )->value( ), truthTable.at( test ).at( 6 ) );
QCOMPARE( ( int ) elm.output( 1 )->value( ), truthTable.at( test ).at( 7 ) );
Expand Down

0 comments on commit 1c902f1

Please sign in to comment.