पर थोड़ा सा है जैसा कि शीर्षक से पता चलता है, क्या यह परीक्षण नाम शीर्ष पर थोड़ा सा है?क्या यह परीक्षण नाम शीर्ष
WhenChargeIsGreaterThanRestingChargeButLessThanChargeRestApproachStep_OnUpdate_ChargeIsSetToRestingCharge
इसे सुधारने के तरीके पर कोई सुझाव? या यह ठीक है जैसा यह है?
नीचे पूरे परीक्षण स्थिरता के रूप में यह खड़ा है तो आप कुछ संदर्भ :)
public class NeuronTests
{
[Fact]
public void OnUpdate_NeuronFiresWhenChargeIsEqualToThreshold()
{
Neuron neuron = new Neuron();
bool fired = false;
neuron.Fired += (s, e) => fired = true;
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
Assert.True(fired, "Neuron didn't fire");
}
[Fact]
public void OnUpdate_NeuronDoesntFireWhenChargeIsLessThanThreshold()
{
Neuron neuron = new Neuron();
bool fired = false;
neuron.Fired += (s, e) => fired = true;
neuron.Charge = Neuron.ChargeThreshold - 1f;
neuron.Update();
Assert.False(fired, "Neuron fired!");
}
[Fact]
public void OnUpdate_NeuronFiresWhenChargeIsGreaterThanThreshold()
{
Neuron neuron = new Neuron();
bool fired = false;
neuron.Fired += (s, e) => fired = true;
neuron.Charge = Neuron.ChargeThreshold + 1f;
neuron.Update();
Assert.True(fired, "Neuron didn't fire");
}
[Fact]
public void WhenNeuronFires_ChargeResetsToRestingCharge()
{
Neuron neuron = new Neuron();
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
Assert.Equal(Neuron.RestingCharge, neuron.Charge);
}
[Fact]
public void AfterFiring_OnUpdate_NeuronWontFire()
{
Neuron neuron = new Neuron();
int fireCount = 0;
neuron.Fired += (s, e) => fireCount++;
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
Assert.Equal(1, fireCount);
}
[Fact]
public void WhenResting_OnUpdate_NeuronWillFire()
{
Neuron neuron = new Neuron();
int fireCount = 0;
neuron.Fired += (s, e) => fireCount++;
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
neuron.Charge = Neuron.ChargeThreshold;
neuron.Update();
Assert.Equal(2, fireCount);
}
[Fact]
public void WhenChargeIsGreaterThanRestingCharge_OnUpdate_ChargeDecreasesTowardsRestingCharge()
{
Neuron neuron = new Neuron();
neuron.Charge = Neuron.RestingCharge + (2 * Neuron.ChargeRestApproachStep);
neuron.Update();
Assert.Equal(Neuron.RestingCharge + Neuron.ChargeRestApproachStep, neuron.Charge);
}
[Fact]
public void WhenChargeIsGreaterThanRestingChargeButLessThanChargeRestApproachStep_OnUpdate_ChargeIsSetToRestingCharge()
{
Neuron neuron = new Neuron();
neuron.Charge = Neuron.RestingCharge + (Neuron.ChargeRestApproachStep * 0.5f);
neuron.Update();
Assert.Equal(Neuron.RestingCharge, neuron.Charge);
}
}
यह एक नाम मैं ऊपर आ जाएगा की तरह दिखता है साथ में। टेस्ट केस के लिए यह एक अद्भुत नाम है!यह बिना किसी टिप्पणी के क्रिस्टल स्पष्ट है, और आपको इसे देखकर पहले रखरखाव प्रोग्रामर की प्रतिक्रिया की कल्पना करने और एक "क्या ???" सोचने की कल्पना की गई है। यदि आप पठनीयता या प्रदर्शन को प्रभावित किए बिना हास्य को अपने कोड में इंजेक्ट कर सकते हैं, तो उतना ही बेहतर होगा। – David
स्पष्ट, संक्षिप्त, स्वयं दस्तावेज ... कोई और क्या चाहता है? –
कुछ दिन उपयोगी हो सकता है जब आपको एक परीक्षण धावक मिला जो नाम निष्पादित कर सकता है। –