var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/dds');

require('../lib/config/mongoose').init(mongoose);
require('../lib/models/acceptanceTest');

var AcceptanceTest = mongoose.model('AcceptanceTest');

var AcceptanceTestActivity = mongoose.model('AcceptanceTestActivity');

var stream = AcceptanceTest.find().stream();

stream.on('data', function(acceptanceTest) {
    var cleanedResults = [];

    acceptanceTest.expectedResults.forEach(function(result) {
        if (result.code.indexOf('_non_calulable') == -1)
            cleanedResults.push(result);
    });

    var diff = cleanedResults.length - acceptanceTest.expectedResults.length;

    if (! diff)
        return console.log(acceptanceTest._id, 'Nothing to do');

    acceptanceTest
        .set('expectedResults', cleanedResults)
        .save(function(err, data) {
            if (err) {
                console.log(acceptanceTest._id);
                return console.trace(err);
            }

            console.log(acceptanceTest._id, 'Removed', diff, 'obsolete values to test');

        });
});

stream.on('end', function() {
    console.log('completed!');
    process.exit();
});

stream.on('error', function(err) {
    console.trace(err);
});


@@ -748,24 +748,223 @@
 g to do');%0A%0A
+    if (! cleanedResults.length) %7B%0A        return acceptanceTest.remove(function(err, product) %7B%0A            console.log(acceptanceTest._id, 'Deleted (all tested values removed)')%0A        %7D);%0A    %7D%0A%0A
     acceptan
@@ -1269,25 +1269,24 @@
  to test');%0A
-%0A
         %7D);%0A

Delete tests that only wrongly tested uncomputable