Skip to content

Commit

Permalink
Possible fix for senecajs#106
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony74 committed Apr 8, 2021
1 parent da4274a commit 810bf7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions problems/sum/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs')
const path = require('path')
const async = require('async')
const _ = require('lodash')
const {getRandomInt} = require('../utils')
const {getRandomInt, pickStaticProps} = require('../utils')
let exercise = require('workshopper-exercise')()

// cleanup for both run and verify
Expand Down Expand Up @@ -46,11 +46,11 @@ exercise.addProcessor(function (mode, callback) {
cb()
}
], (err, results) => {
submissionResult = results[0]
submissionResult = pickStaticProps(results[0])
if (mode === 'run') {
console.log(`Execution with left: ${a}, right: ${b} returned: ${JSON.stringify(submissionResult)}`)
} else {
solutionResult = results[1]
solutionResult = pickStaticProps(results[1])
if (!_.isEqual(solutionResult, submissionResult)) {
exercise.emit('fail', `Expected result: ${JSON.stringify(solutionResult)}` +
`, Actual result: ${JSON.stringify(submissionResult)}`)
Expand Down
12 changes: 12 additions & 0 deletions problems/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const _ = require('lodash')

exports.getRandomInt = (min = 0, max = 100) => {
min = Math.ceil(min)
max = Math.floor(max)
Expand All @@ -12,3 +14,13 @@ exports.getRandomFloat = (min = 0, max = 100) => {
const num = Math.floor(Math.random() * (max - min)) + min
return Math.round(num * 10) / 100
}

exports.pickStaticProps = (result) => {
const staticProps = [
'pattern', 'action', 'tag', 'seneca', 'version', 'timeout', 'custon', 'plugin', 'parents',
'remote', 'sync', 'trace', 'sub', 'data', 'err', 'err_trace', 'error', 'empty'
]
result[1] = _.pick(result[1], staticProps)
return result
}

0 comments on commit 810bf7f

Please sign in to comment.