狠狠撸

狠狠撸Share a Scribd company logo
???? ? ?? ???? ??? 
2014-12-09 ? ? ?
?? ?? ? ???? 
? Node.js? ??? ??? ????. 
? ?? ? ??????? 
? ??? ???? ?. ??? ?.
?? ? ??????? 
? ?? ???? ? ??? 7? 
? 2? ?????? ???? ??? ??? ???? ?? 
=> ? ?? 
? ???? ???? ?? ? ????? ?? ??? ?? 
=> ?????? ? ?? ????? ?? ???!
?? ? ??????? 
? ???? ?? ?? ?? 
- ?? ??? ??? ?? ????. ?? ? ????(??) 
- ????? ?????? ??? ?? ???(??) 
? ???? ? ??? ?? 
- ???? ? 6?? ???? ???? ? 3?? ? ?? 
- ?? 1???? ?? ????? ?? 
- ?? ??? ??? ??? 5? ? ???? ?? 
?, ???? ?? ? ???? ?? ?? ?? ??
??? ???? ?. ??? ?. 
? ??? ?? ??! 
“???? ? ?? ??? ???? ??? 
???? ? ? ???… 
Java + Spring? ????…” 
=> ??? ???? ????????? 
????????? ?? ? ?? Node.js ??
??? ???? ?. ??? ?. 
Node.js ???? + ???????/Express ??? ?? ??
??? ???? ?. ??? ?. 
[??? ????] 
1. HTTP? ?? URL ?? 
2. Node.js ?? Express? 
?? ? Controller ?? 
3. ?????? ?? ? 
??? EJS?? ?? 
4. ???? EJS? ???? 
??? ?????? ? 
5. node-schedule? 
???? ????? 
???? ????? ??
??? ???? ?. ??? ?. 
http://bluepoet1004.cafe24.com:4000/users
??? ???? ?. ??? ?. 
? ???? ?! ??? I/O 
=> Node.js? ???????? ??? I/O? ??? 
??? ?? : http://www.techthali.org/node-js-asynchronous-non-blocking-events-callbacks/
??? ???? ?. ??? ?. 
? ???? ?! ??? I/O 
client.query('SELECT first_id, after_id FROM ' + TABLE + ' where DATE_ADD(create_date, 
INTERVAL 7 DAY) > NOW() AND create_date < NOW();select * from member order by 
id', function(err, rows, fields) { 
???? 
if(err) { 
throw err; 
} 
res.render('userList', { 
users: rows[1], 
prevUsers: rows[0], 
title: 'Listing Developmemt Team CodeReview Matching Result' 
}); 
}); 
??? I/O? ??? ????? ????, DB?? ??? ???? 
???? ???? ????? ????? ? ????!
??? ???? ?. ??? ?. 
? ???? ?! ??? I/O 
client.query('SELECT * FROM member', function(err, results, fields) { 
client.query('SELECT first_id, after_id FROM ' + TABLE + ' where DATE_ADD(create_date, INTERVAL 7 
DAY) > NOW() AND create_date < NOW();select * from member order by id', function(err, rows, fields) { 
???? 
if(err) { 
throw err; 
} 
console.log('results ' + results[0].name); 
res.render('userList', { 
users: rows[1], 
prevUsers: rows[0], 
title: 'Listing Developmemt Team CodeReview Matching Result' 
}); 
}); 
}); 
???? ????? ???? ????(???) ??? ??? ?? 
?? ????? ????? results(????)? ??? ? ??!
??? ???? ?. ??? ?. 
? ??? ?! “????”? ????! 
“??, Node.js? ? ??? ??? ??/????? 
?? ???? ?? ???? ??? ????? 
???(Decorator)? ??? ? ??….”
??? ???? ?. ??? ?. 
? ??? ?! “????”? ????! 
?? ????? ??? ???? 
getRandomNumber(selectedNumber); 
??? ? ????? ??! 
??? ???? ?? ??? ? ???.. 
???.. ?? ??? ????... 
???? ?? ???, ??? ?? ??. 
?? “??? ????!” 
getRandomNumber: function(selectedNumber) { 
???? 
var me = this; 
var randomNumbers = [1,2,3,4,5,6]; 
randomNumbers.splice(randomNumbers.indexOf(selectedNumber), 1); 
var prevPairNumber = me.prevPair.get(selectedNumber); 
if(prevPairNumber !== undefined) { 
randomNumbers.splice(randomNumbers.indexOf(prevPairNumber), 1); 
} 
for(var i=0; i<me.leftNumbers.length; i++) { 
if(randomNumbers.indexOf(me.leftNumbers[i]) == -1) { 
continue; 
} 
randomNumbers.splice(randomNumbers.indexOf(me.leftNumbers[i]), 1); 
} 
if(randomNumbers.length == 3) { 
var deleteNumber = randomNumbers.slice(0); 
for(var i=0; i<randomNumbers.length; i++) { 
if(me.prevPair.get(randomNumbers[i]) !== undefined) { 
var key = randomNumbers[i]; 
var value = me.prevPair.get(randomNumbers[i]); 
deleteNumber.splice(deleteNumber.indexOf(key), 1); 
deleteNumber.splice(deleteNumber.indexOf(value), 1); 
break; 
} 
} 
randomNumbers.splice(randomNumbers.indexOf(deleteNumber[0]), 1); 
} 
var randomNumbersCnt = randomNumbers.length; 
var randomNumberIndex = Math.floor(Math.random() * (randomNumbersCnt - 
1 + 1)) + 1; 
return randomNumbers[randomNumberIndex-1]; 
},
??? ???? ?. ??? ?. 
? ??? ?! “?????”? ? ????! 
“???? ??, ????? ??? ? ??? 
????? ??. 
???… 
? ??? ???? ??? ??? ???? ? ???…”
??? ???? ?. ??? ?. 
? ??? ?! “?????”? ? ????! 
test/codeReviewPairLogicTest.js 
???? 
var assert = require('assert'); 
var pair = require('../pair'); 
var Map = require('./map'); 
before(function() { 
pair.init(); 
pair.prevPair = new Map(); 
pair.result = new Map(); 
pair.prevPair.put(1, 5); 
pair.prevPair.put(2, 6); 
pair.prevPair.put(3, 4); 
}); 
describe('[CodeReviewMatchingPair]PairLogicConfirm Test Suite', function() { 
describe('CodeReviewPair Result Confirm', function() { 
it('result count is 3, the key and value of the map is not the same', function() { 
pair.fakeExtractPrevMembers(); 
assert.equal(pair.result.size(), 3); 
var keys = pair.result.keys(); 
for(var i=0; i< keys.length; i++) { 
assert.notEqual(keys[i] != pair.result.get(keys[i]), false); 
} 
}); 
}); 
});
??? ???? ?. ??? ?. 
? ??? ?! “?????”? ? ????! 
“done()??” ??? “??????” ??! test/dbDataConfirmTest.js 
???? 
var assert = require('assert'); 
var db = require('./db'); 
var repo = require('../repository'); 
before(function() { 
repo.getMembers(); 
}); 
describe('[CodeReviewMatchingPair]DbDataConfirmTest Test Suite', function() { 
describe('Total Member Count : Direct Query', function() { 
it('All Member is six', function(done) { 
db.query('SELECT * FROM member', function(err, rows, fields) { 
if(err) { 
throw err; 
} 
assert.equal(rows.length, 6); 
done(); 
}); 
}); 
}); 
describe('CodeReview Member Data Confirm', function() { 
it('CodeReview Member Data Confirm', function(done) { 
db.query('SELECT first_id, after_id FROM member_match_list where DATE_ADD(create_date, INTERVAL 7 DAY) > NOW() AND create_date < NOW()', function(err, rows, fields) { 
if(err) { 
throw err; 
} 
assert.equal(rows.length, 3); 
for(var i=0; i< rows.length; i++) { 
assert.notEqual(rows[i].first_id != rows[i].after_i, false); 
} 
done(); 
}); 
}); 
}); 
describe('Total Member Count : Other Module Called', function() { 
it('All Member is six', function() { 
assert.equal(repo.result.length, 6); 
}); 
}); 
});
??? ???? ?. ??? ?. 
? ??? ?! “?????”? ? ????! 
- Node.js Test Framework? “Mocha”? 
Node.js ?? “assert ??”? ????? ??
??? ???? ?. ??? ?. 
? ??? ?! “?????”? ? ????! 
- BDD(behavior-driven development)? ??? 
???????? ?? “?? ?? ??? ?? 
?? ? ?? ????? ?? ???” ??!
? ????/?????? ?? 
https://github.com/bluepoet/CodeReviewMatchingPair
?

More Related Content

???? ? ?? ???? ???

  • 1. ???? ? ?? ???? ??? 2014-12-09 ? ? ?
  • 2. ?? ?? ? ???? ? Node.js? ??? ??? ????. ? ?? ? ??????? ? ??? ???? ?. ??? ?.
  • 3. ?? ? ??????? ? ?? ???? ? ??? 7? ? 2? ?????? ???? ??? ??? ???? ?? => ? ?? ? ???? ???? ?? ? ????? ?? ??? ?? => ?????? ? ?? ????? ?? ???!
  • 4. ?? ? ??????? ? ???? ?? ?? ?? - ?? ??? ??? ?? ????. ?? ? ????(??) - ????? ?????? ??? ?? ???(??) ? ???? ? ??? ?? - ???? ? 6?? ???? ???? ? 3?? ? ?? - ?? 1???? ?? ????? ?? - ?? ??? ??? ??? 5? ? ???? ?? ?, ???? ?? ? ???? ?? ?? ?? ??
  • 5. ??? ???? ?. ??? ?. ? ??? ?? ??! “???? ? ?? ??? ???? ??? ???? ? ? ???… Java + Spring? ????…” => ??? ???? ????????? ????????? ?? ? ?? Node.js ??
  • 6. ??? ???? ?. ??? ?. Node.js ???? + ???????/Express ??? ?? ??
  • 7. ??? ???? ?. ??? ?. [??? ????] 1. HTTP? ?? URL ?? 2. Node.js ?? Express? ?? ? Controller ?? 3. ?????? ?? ? ??? EJS?? ?? 4. ???? EJS? ???? ??? ?????? ? 5. node-schedule? ???? ????? ???? ????? ??
  • 8. ??? ???? ?. ??? ?. http://bluepoet1004.cafe24.com:4000/users
  • 9. ??? ???? ?. ??? ?. ? ???? ?! ??? I/O => Node.js? ???????? ??? I/O? ??? ??? ?? : http://www.techthali.org/node-js-asynchronous-non-blocking-events-callbacks/
  • 10. ??? ???? ?. ??? ?. ? ???? ?! ??? I/O client.query('SELECT first_id, after_id FROM ' + TABLE + ' where DATE_ADD(create_date, INTERVAL 7 DAY) > NOW() AND create_date < NOW();select * from member order by id', function(err, rows, fields) { ???? if(err) { throw err; } res.render('userList', { users: rows[1], prevUsers: rows[0], title: 'Listing Developmemt Team CodeReview Matching Result' }); }); ??? I/O? ??? ????? ????, DB?? ??? ???? ???? ???? ????? ????? ? ????!
  • 11. ??? ???? ?. ??? ?. ? ???? ?! ??? I/O client.query('SELECT * FROM member', function(err, results, fields) { client.query('SELECT first_id, after_id FROM ' + TABLE + ' where DATE_ADD(create_date, INTERVAL 7 DAY) > NOW() AND create_date < NOW();select * from member order by id', function(err, rows, fields) { ???? if(err) { throw err; } console.log('results ' + results[0].name); res.render('userList', { users: rows[1], prevUsers: rows[0], title: 'Listing Developmemt Team CodeReview Matching Result' }); }); }); ???? ????? ???? ????(???) ??? ??? ?? ?? ????? ????? results(????)? ??? ? ??!
  • 12. ??? ???? ?. ??? ?. ? ??? ?! “????”? ????! “??, Node.js? ? ??? ??? ??/????? ?? ???? ?? ???? ??? ????? ???(Decorator)? ??? ? ??….”
  • 13. ??? ???? ?. ??? ?. ? ??? ?! “????”? ????! ?? ????? ??? ???? getRandomNumber(selectedNumber); ??? ? ????? ??! ??? ???? ?? ??? ? ???.. ???.. ?? ??? ????... ???? ?? ???, ??? ?? ??. ?? “??? ????!” getRandomNumber: function(selectedNumber) { ???? var me = this; var randomNumbers = [1,2,3,4,5,6]; randomNumbers.splice(randomNumbers.indexOf(selectedNumber), 1); var prevPairNumber = me.prevPair.get(selectedNumber); if(prevPairNumber !== undefined) { randomNumbers.splice(randomNumbers.indexOf(prevPairNumber), 1); } for(var i=0; i<me.leftNumbers.length; i++) { if(randomNumbers.indexOf(me.leftNumbers[i]) == -1) { continue; } randomNumbers.splice(randomNumbers.indexOf(me.leftNumbers[i]), 1); } if(randomNumbers.length == 3) { var deleteNumber = randomNumbers.slice(0); for(var i=0; i<randomNumbers.length; i++) { if(me.prevPair.get(randomNumbers[i]) !== undefined) { var key = randomNumbers[i]; var value = me.prevPair.get(randomNumbers[i]); deleteNumber.splice(deleteNumber.indexOf(key), 1); deleteNumber.splice(deleteNumber.indexOf(value), 1); break; } } randomNumbers.splice(randomNumbers.indexOf(deleteNumber[0]), 1); } var randomNumbersCnt = randomNumbers.length; var randomNumberIndex = Math.floor(Math.random() * (randomNumbersCnt - 1 + 1)) + 1; return randomNumbers[randomNumberIndex-1]; },
  • 14. ??? ???? ?. ??? ?. ? ??? ?! “?????”? ? ????! “???? ??, ????? ??? ? ??? ????? ??. ???… ? ??? ???? ??? ??? ???? ? ???…”
  • 15. ??? ???? ?. ??? ?. ? ??? ?! “?????”? ? ????! test/codeReviewPairLogicTest.js ???? var assert = require('assert'); var pair = require('../pair'); var Map = require('./map'); before(function() { pair.init(); pair.prevPair = new Map(); pair.result = new Map(); pair.prevPair.put(1, 5); pair.prevPair.put(2, 6); pair.prevPair.put(3, 4); }); describe('[CodeReviewMatchingPair]PairLogicConfirm Test Suite', function() { describe('CodeReviewPair Result Confirm', function() { it('result count is 3, the key and value of the map is not the same', function() { pair.fakeExtractPrevMembers(); assert.equal(pair.result.size(), 3); var keys = pair.result.keys(); for(var i=0; i< keys.length; i++) { assert.notEqual(keys[i] != pair.result.get(keys[i]), false); } }); }); });
  • 16. ??? ???? ?. ??? ?. ? ??? ?! “?????”? ? ????! “done()??” ??? “??????” ??! test/dbDataConfirmTest.js ???? var assert = require('assert'); var db = require('./db'); var repo = require('../repository'); before(function() { repo.getMembers(); }); describe('[CodeReviewMatchingPair]DbDataConfirmTest Test Suite', function() { describe('Total Member Count : Direct Query', function() { it('All Member is six', function(done) { db.query('SELECT * FROM member', function(err, rows, fields) { if(err) { throw err; } assert.equal(rows.length, 6); done(); }); }); }); describe('CodeReview Member Data Confirm', function() { it('CodeReview Member Data Confirm', function(done) { db.query('SELECT first_id, after_id FROM member_match_list where DATE_ADD(create_date, INTERVAL 7 DAY) > NOW() AND create_date < NOW()', function(err, rows, fields) { if(err) { throw err; } assert.equal(rows.length, 3); for(var i=0; i< rows.length; i++) { assert.notEqual(rows[i].first_id != rows[i].after_i, false); } done(); }); }); }); describe('Total Member Count : Other Module Called', function() { it('All Member is six', function() { assert.equal(repo.result.length, 6); }); }); });
  • 17. ??? ???? ?. ??? ?. ? ??? ?! “?????”? ? ????! - Node.js Test Framework? “Mocha”? Node.js ?? “assert ??”? ????? ??
  • 18. ??? ???? ?. ??? ?. ? ??? ?! “?????”? ? ????! - BDD(behavior-driven development)? ??? ???????? ?? “?? ?? ??? ?? ?? ? ?? ????? ?? ???” ??!
  • 19. ? ????/?????? ?? https://github.com/bluepoet/CodeReviewMatchingPair
  • 20. ?