你愛睡覺嗎?
醒著的時候,腦中其實會產生很多有毒物質。研究發現,睡眠的時候腦細胞會收縮,腦細胞間的空間變大,讓腦脊髓液的流動更暢通,更容易代謝有毒物質。有毒物質如果沒有被排除一直累積在腦中,會讓你的無論是思考、學習、做決定都鈍鈍的。
![]() |
| credit: snaulkter CC 2.0 |
![]() |
| credit: Hafiz Issadeen CC 2.0 |
describe('FizzBuzz', function() {
it('outputs the original number if the input number is not multiple of 3 or 7,
function() {
expect(fizzbuzz(1)).toBe("1");
expect(fizzbuzz(2)).toBe("2");
expect(fizzbuzz(4)).toBe("4");
});
it('outputs "fizz" if the input number is multiple of 3', function() {
expect(fizzbuzz(3)).toBe("fizz");
expect(fizzbuzz(6)).toBe("fizz");
expect(fizzbuzz(9)).toBe("fizz");
});
it('outputs "buzz" if the input number is multiple of 7', function() {
expect(fizzbuzz(7)).toBe("buzz");
expect(fizzbuzz(14)).toBe("buzz");
expect(fizzbuzz(28)).toBe("buzz");
});
it('outputs "fizzbuzz" if the input number is multiple of 7 and 3',
function() {
expect(fizzbuzz(21)).toBe("fizzbuzz");
});
});
![]() |
| karam 一次幫我搞定四個瀏覽器,非常盡責 |
module.exports = function(config) {
config.set({
basePath: '../',
// 使用 jasmine test framework
frameworks: ['jasmine'],
// 哪些 file 要載入測試。陷阱注意:順序很重要
files: [
'test/phantomjs-fix.js',
'js/angular.min.js',
'test/angular-mocks.js',
'js/volume_dialog.js',
'test/spec/*spec.js'
],
// 產生 progress 訊息與 junit report
reporters: ['progress', 'junit'],
// junit report 檔案名稱
junitReporter: {
outputFile: 'test-results.xml',
suites: ''
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
// 要在哪些瀏覽器上面執行
browsers: ['Chrome', 'Firefox', 'Safari', 'PhantomJS'],
singleRun: false
});
};
設定裡頭有兩個陷阱,一是一定要把 angular-mock.js 加入到 files 裡,二是 files 是有順序性的,angular.js 在前,angular-mock*.js 要在後。搞這個就搞死我了。
// phantomjs-fix.js
// phantomJs does not support bind().
// See https://github.com/ractivejs/ractive/issues/679
Function.prototype.bind = Function.prototype.bind || function (thisp) {
var fn = this;
return function () {
return fn.apply(thisp, arguments);
};
};
[TestMethod]
public void TestThattSumOfAllParamsAreSavedToDB()
{
FakeDB db = new FakeDB();
Class1 c1 = new Class1(db);
c1.sum(1, 2, 3, 4);
Assert.AreEqual(1 + 2 + 3 + 4, db.SavedSum);
}
class FakeDB : DBInterface
{
public int SavedSum { get; private set; }
public SaveValue(int value)
{
this.SavedSum = value;
}
}
interface DBInterface
{
void SaveValue(int value);
}
class Class1
{
private DBInterface db;
public Class1(DBInterface db)
{
this.db = db;
}
public void SumToDB(params int[] values)
{
int total = 0;
foreach (int value in values)
total += value;
this.db.SaveValue(total);
}
}
public void TestThattSumOfAllParamsAreSavedToDB()
{
Moq.Mock<DBInterface>db = new Moq.Mock<DBInterface>();
db.Setup(x => x.SaveValue(1+2+3+4)).Verifiable();
Class1 c1 = new Class1(db.Object);
c1.sum(1, 2, 3, 4);
db.VerifyAll();
}
kernel開發者喜歡被大家看成是個受過教育的人,所以字要拼對,才能製造這種好印象。不要用一些跛腳的字眼,像是"dont",要用"do not" 或是 "don't"。訊息文字要扼要 清楚 精確。
kernel訊息文字結尾不需要句點。
列印數字的時候加上括號(%d)是毫無意義的,應該避免。
在linux/device.h中有專為driver提供的巨集,可以方便的印出適合訊息文字,如dev_err() dev_warn() dev_info()。要印出與driver無關的訊息,可以用linux/printk.h中的pr_debug()或是pr_info()。
雖然有些人打死不用goto,但在kernel裡goto還是很好用的,尤其是goto到function最後統一處理些資源回收的工作。另外: