Skip to content

Commit 1724805

Browse files
committed
killing the spy killing (-_-)
1 parent 9a630eb commit 1724805

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

test/base/trainopts.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,89 +79,78 @@ describe('train() and trainAsync() use the same private methods', () => {
7979
let trainingData = [{ input: [0, 0], output: [0] }];
8080
let opts = { iterations:1 };
8181
let net = new brain.NeuralNetwork();
82+
let methodsChecked = [
83+
'_prepTraining',
84+
'_updateTrainingOptions',
85+
'_formatData',
86+
'_verifyIsInitialized',
87+
'_trainingTick'
88+
];
8289

83-
function getSpy (net, func) {
84-
sinon.spy(net, func);
85-
}
86-
87-
function killSpy (net, func) {
88-
net[func].restore();
89-
}
90+
beforeEach(() => { methodsChecked.forEach(m => sinon.spy(net, m)); })
91+
afterEach(() => { methodsChecked.forEach(m => net[m].restore()); })
9092

9193
it('_prepTraining()', (done) => {
92-
getSpy(net, '_prepTraining');
9394
net.train(trainingData, opts);
9495
assert(net._prepTraining.calledOnce, `_prepTraining was expected to be called once but was called ${net._prepTraining.callCount}`);
9596
net
9697
.trainAsync(trainingData, opts)
9798
.then(() => {
9899
assert(net._prepTraining.calledTwice, `_prepTraining was expected to be called twice but was called ${net._prepTraining.callCount}`);
99-
killSpy(net, '_prepTraining');
100100
done();
101101
})
102102
.catch(e => {
103103
assert.ok(false, e.toString());
104-
killSpy(net, '_prepTraining');
105104
done()
106105
});
107106
});
108107

109108
it('_updateTrainingOptions()', (done) => {
110-
getSpy(net, '_updateTrainingOptions');
111109
net.train(trainingData, opts);
112110
assert(net._updateTrainingOptions.calledOnce, `_updateTrainingOptions was expected to be called once but was called ${net._updateTrainingOptions.callCount}`);
113111
net
114112
.trainAsync(trainingData, opts)
115113
.then(() => {
116114
assert(net._updateTrainingOptions.calledTwice, `_updateTrainingOptions was expected to be called twice but was called ${net._prepTraining.callCount}`);
117-
killSpy(net, '_updateTrainingOptions');
118115
done();
119116
})
120117
.catch(e => {
121118
assert.ok(false, e.toString());
122-
killSpy(net, '_updateTrainingOptions');
123119
done()
124120
});
125121
});
126122

127123
it('_formatData()', (done) => {
128-
getSpy(net, '_formatData');
129124
net.train(trainingData, opts);
130125
assert(net._formatData.calledOnce, `_formatData was expected to be called once but was called ${net._formatData.callCount}`);
131126
net
132127
.trainAsync(trainingData, opts)
133128
.then(() => {
134129
assert(net._formatData.calledTwice, `_formatData was expected to be called twice but was called ${net._prepTraining.callCount}`);
135-
killSpy(net, '_formatData');
136130
done();
137131
})
138132
.catch(e => {
139133
assert.ok(false, e.toString());
140-
killSpy(net, '_formatData');
141134
done()
142135
});
143136
});
144137

145138
it('_verifyIsInitialized()', (done) => {
146-
getSpy(net, '_verifyIsInitialized');
147139
net.train(trainingData, opts);
148140
assert(net._verifyIsInitialized.calledOnce, `_verifyIsInitialized was expected to be called once but was called ${net._verifyIsInitialized.callCount}`);
149141
net
150142
.trainAsync(trainingData, opts)
151143
.then(() => {
152144
assert(net._verifyIsInitialized.calledTwice, `_verifyIsInitialized was expected to be called twice but was called ${net._prepTraining.callCount}`);
153-
killSpy(net, '_verifyIsInitialized');
154145
done();
155146
})
156147
.catch(e => {
157148
assert.ok(false, e.toString());
158-
killSpy(net, '_verifyIsInitialized');
159149
done()
160150
});
161151
});
162152

163153
it('_trainingTick()', (done) => {
164-
getSpy(net, '_trainingTick');
165154
net.train(trainingData, opts);
166155
// The loop calls _trainingTick twice and returns imidiatly on second call
167156
assert(net._trainingTick.calledTwice, `_trainingTick was expected to be called twice but was called ${net._prepTraining.callCount}`);
@@ -170,12 +159,10 @@ describe('train() and trainAsync() use the same private methods', () => {
170159
.then(() => {
171160
// trainAsync only calls _trainingTick once
172161
assert(net._trainingTick.calledThrice, `_trainingTick was expected to be called thrice but was called ${net._prepTraining.callCount}`);
173-
killSpy(net, '_trainingTick');
174162
done();
175163
})
176164
.catch(e => {
177165
assert.ok(false, e.toString());
178-
killSpy(net, '_trainingTick');
179166
done()
180167
});
181168
});

0 commit comments

Comments
 (0)