jingoro2112 / wrench

practical embedded script interpreter
MIT License
106 stars 9 forks source link

Remove and exist are not working properly. #29

Closed MaxTymchii closed 3 months ago

MaxTymchii commented 3 months ago

Here are the tests that I was trying to do with hashtable

var table = {:};
table["mock"] = 96;
table._remove("mock");
var valueIsNotExist = table._exist("mock");
assertEqual( valueIsNotExist, false, "table mock should not exist" );
var mockValue = table["mock"];
assertEqual( mockValue, null, "table mock should be null" );

var table2 = {:};
table2[2] = 45;
assertEqual( table2[2]._count, 1, "table2 should have 1 element");
assertEqual( table2[2], 45, "table2 should have 45" );
var valueIsExist = table2._exist(2);
assertEqual( valueIsExist, true, "table2 should have 2" );
table2._remove(2);
valueIsExist = table2._exist(2);
assertEqual( valueIsExist, false, "table2 should not have 2" );

var table3 = {:};

table3["one"] = 96;
table3["two"] = 97;
table3["three"] = 98;

assertEqual( table3._count, 3, "table3 should have 3 elements" );
assertEqual( table3["one"], 96, "table3 should have 96" );
assertEqual( table3["two"], 97, "table3 should have 97" );
assertEqual( table3["three"], 98, "table3 should have 98" );

var table3IsExist = table3._exist("one");
assertEqual( table3IsExist, false, "table3 should have one" );

table3._remove("one");
assertEqual( table3._count, 2, "table3 should have 2 elements" );
var table3IsExist1 = table3._exist("one");
assertEqual( table3IsExist1, false, "table3 should not have one" );

println("=======table=========");
for (var key, var value : table) {
    println(key);
    println(value);
}

println("=======table2=========");
for (var key, var value : table2) {
    println(key);
    println(value);
}

My results


FAIL: mock should be empty
FAIL: table mock should not exist
FAIL: table mock should be null
FAIL: table2 should have 1 element
PASS: table2 should have 45
FAIL: table2 should have 2
PASS: table2 should not have 2
FAIL: table3 should have 3 elements
PASS: table3 should have 96
PASS: table3 should have 97
PASS: table3 should have 98
FAIL: table3 should have one
FAIL: table3 should have 2 elements
FAIL: table3 should not have one
=======table=========
mock
96
=======table2=========
923577301
0

Assert function that I use now.

function assertEqual(actual, expected, comment) {
  var message = "";
  var equal = false;

    equal = actual == expected;  

  if (equal) {
    str::sprintf(message, "PASS: %s", comment);
  } else {
    str::sprintf(message, "FAIL: %s", comment);
  }

  println(message);
}
jingoro2112 commented 3 months ago

these are all fixed as of 5.0.1