Сţµç×ÓÊé > ÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ26ÕÂ

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ26ÕÂ

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ3500×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡




it¡¡as¡¡a¡¡search¡¡solution£»¡¡where¡¡a¡¡method¡¡iterates¡¡over¡¡a¡¡string¡¡and¡¡attempts¡¡to¡¡match¡¡elements¡¡¡¡

of¡¡a¡¡buffer¡¡to¡¡some¡¡text¡¡that¡¡is¡¡being¡¡searched¡£¡¡The¡¡work¡­in¡­progress¡¡code¡¡is¡¡shown¡¡in¡¡Figure¡¡3¡­8¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡test¡¡code¡¡is¡¡not¡¡shown¡¡here£»¡¡because¡¡it¡¡is¡¡similar¡¡to¡¡that¡¡for¡¡the¡¡previous¡¡solution£»¡¡with¡¡¡¡

the¡¡difference¡¡being¡¡the¡¡method¡¡being¡¡tested¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡84¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

62¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IndexOf£¨£©¡¡attempts¡¡to¡¡match¡¡the¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡text¡¡¡°allo¡±¡¡in¡¡the¡¡variable¡¡buffer¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Work¡­in¡­progress¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡text¡¡is¡¡found£»¡¡an¡¡offset¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡is¡¡not¡¡¡­1¡¡is¡¡returned¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡FindSubstring£¨ByVal¡¡buffer¡¡As¡¡String£©_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡buffer¡£IndexOf£¨¡¨allo¡¨£©¡¡¡¡¡­1¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Translator¡£TranslateHello£¨¡¨allo¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IndexOf£¨£©¡¡returns¡¡the¡¡index¡¡of¡¡the¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡first¡¡matched¡¡character£»¡¡which¡¡is¡¡2¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡will¡¡always¡¡start¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡¡¡¡¡¡¡l¡¡¡¡¡¡¡¡l¡¡¡¡¡¡¡¡o¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡counting¡¡with¡¡the¡¡value¡¡0¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Index¡¡0¡¡¡¡¡¡¡¡¡¡¡¡1¡¡¡¡¡¡2¡¡¡¡¡¡¡¡3¡¡¡¡¡¡¡¡4¡¡¡¡¡¡¡¡¡¡5¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­8¡£¡¡Finding¡¡a¡¡substring¡¡to¡¡solve¡¡the¡¡whitespace¡¡problem¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Which¡¡Is¡¡the¡¡Best¡¡Solution£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Take¡¡a¡¡moment¡¡to¡¡think¡¡about¡¡which¡¡is¡¡the¡¡best¡¡solution£º¡¡trimming¡¡the¡¡whitespace¡¡or¡¡finding¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡substring¡£¡¡The¡¡answer¡¡is¡¡neither¡¡is¡¡perfect£»¡¡each¡¡solution¡¡has¡¡its¡¡problems¡£¡¡This¡¡is¡¡a¡¡very¡¡mon¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡occurrence¡¡when¡¡you¡¡are¡¡developing¡¡software¡£¡¡You¡¡think¡¡you¡¡have¡¡all¡¡the¡¡corners¡¡covered£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡another¡¡scenario¡¡causes¡¡your¡¡software¡¡to¡¡fail¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Again£»¡¡I¡¡want¡¡to¡¡stress¡¡that¡¡you¡¡need¡¡to¡¡write¡¡more¡¡tests¡¡to¡¡figure¡¡out¡¡which¡¡scenarios¡¡might¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cause¡¡your¡¡software¡¡to¡¡fail¡£¡¡For¡¡the¡¡solution¡¡of¡¡trimming¡¡whitespace£»¡¡writing¡¡another¡¡test¡¡causes¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡it¡¡to¡¡fail£»¡¡as¡¡shown¡¡in¡¡the¡¡following¡¡code¡£¡¡It¡¡cannot¡¡be¡¡tweaked¡¡to¡¡make¡¡the¡¡test¡¡succeed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡verifyValue¡¡As¡¡String¡¡=¡¡TrimmingWhitespace£¨¡¨a¡¡¡¡allo¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡verifyValue¡£pareTo£¨¡¨hallo¡¨£©¡¡¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Test¡¡failed£º¡¡cannot¡¡parse¡¡multiple¡¡words¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡test£»¡¡the¡¡leading¡¡¡°a¡±¡¡is¡¡considered¡¡the¡¡first¡¡character¡¡and¡¡is¡¡not¡¡trimmed¡£¡¡The¡¡verification¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡fail¡¡because¡¡pareTo£¨£©¡¡cannot¡¡verify¡¡the¡¡misaligned¡¡buffer¡¡caused¡¡by¡¡the¡¡leading¡¡¡°a¡£¡±¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡new¡¡test¡¡were¡¡executed¡¡against¡¡the¡¡substring¡¡solution£»¡¡it¡¡would¡¡succeed¡¡and¡¡find¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡word¡¡¡°allo¡£¡±¡¡Because¡¡the¡¡new¡¡test¡¡caused¡¡the¡¡first¡¡solution¡¡to¡¡fail£»¡¡it¡¡would¡¡seem¡¡that¡¡solution¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡no¡­go¡£¡¡Our¡¡confidence¡¡has¡¡been¡¡increased¡¡in¡¡the¡¡second¡¡solution¡¡because¡¡the¡¡old¡¡test¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡new¡¡test¡¡did¡¡not¡¡fail¡£¡¡But¡¡don¡¯t¡¡be¡¡too¡¡hasty¡¡to¡¡consider¡¡that¡¡as¡¡the¡¡best¡¡path¡£¡¡The¡¡substring¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solution¡¡fails¡¡with¡¡the¡¡following¡¡test¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡verifyValue¡¡As¡¡String¡¡=¡¡FindSubstring£¨¡¨allodium¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡verifyValue¡£pareTo£¨¡¨hallo¡¨£©¡¡¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨allodium¡¡to¡¡hallo¡¡test¡¡failed¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡85¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡PU¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡S¡¡¡¡63¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡word¡¡tested£»¡¡¡°allodium£»¡±¡¡contains¡¡the¡¡characters¡¡allo¡£¡¡The¡¡verification¡¡will¡¡succeed£»¡¡¡¡

and¡¡this¡¡is¡¡an¡¡example¡¡of¡¡a¡¡false¡¡positive¡£¡¡



¡öNote¡¡¡¡It¡¡is¡¡important¡¡to¡¡have¡¡many¡¡tests¡¡that¡¡verify¡¡a¡¡multitude¡¡of¡¡different¡¡scenarios¡£¡¡You¡¡should¡¡have¡¡tests¡¡¡¡

that¡¡are¡¡supposed¡¡to¡¡succeed¡¡and¡¡those¡¡that¡¡are¡¡supposed¡¡to¡¡fail¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡conclusion¡¡is¡¡that¡¡neither¡¡of¡¡the¡¡solutions¡¡works¡¡properly¡£¡¡With¡¡extended¡¡testing£»¡¡each¡¡¡¡

solution¡¡created¡¡new¡¡problems¡£¡¡We¡¡need¡¡to¡¡find¡¡another¡¡solution¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡DEVELOPMENT¡¡FRUSTRATIONS¡¡



¡¡¡¡¡¡It¡¡would¡¡seem¡¡that¡¡creating¡¡solutions¡¡and¡¡then¡¡creating¡¡tests¡¡that¡¡nullify¡¡the¡¡solution¡¡is¡¡a¡¡lesson¡¡in¡¡frustration¡£¡¡¡¡

¡¡¡¡¡¡You¡¡create¡¡code¡¡that¡¡does¡¡not¡¡solve¡¡the¡¡problems¡£¡¡What¡¡you¡¡must¡¡realize¡¡and¡¡take¡¡to¡¡heart¡¡is¡¡that¡¡this¡¡is¡¡part¡¡¡¡

¡¡¡¡¡¡of¡¡the¡¡software¡¡development¡¡process¡£¡¡Yes£»¡¡some¡¡people¡¡write¡¡code¡¡and¡¡don¡¯t¡¡worry¡¡about¡¡the¡¡tests£»¡¡but¡¡those¡¡¡¡

¡¡¡¡¡¡developers¡¡give¡¡software¡¡development¡¡a¡¡bad¡¡name¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡want¡¡to¡¡be¡¡a¡¡trustworthy¡¡developer¡¡who¡¡tests¡¡your¡¡code¡£¡¡I¡¡have¡¡been£»¡¡and¡¡my¡¡wife¡¡is£»¡¡a¡¡software¡¡¡¡

¡¡¡¡¡¡development¡¡manager¡£¡¡In¡¡her¡¡words£»¡¡¡°I¡¡can¡¡deal¡¡with¡¡slow¡¡developers£»¡¡but¡¡I¡¡cannot¡¡deal¡¡with¡¡developers¡¡who¡¡¡¡

¡¡¡¡¡¡I¡¡cannot¡¡trust¡¡to¡¡write¡¡stable¡¡and¡¡robust¡¡code¡£¡¡The¡¡problem¡¡with¡¡untrustworthy¡¡developers¡¡is¡¡that¡¡I¡¡cannot¡¡let¡¡¡¡

¡¡¡¡¡¡them¡¡release¡¡code¡¡into¡¡production¡¡and¡¡always¡¡have¡¡to¡¡have¡¡somebody¡¡looking¡¡over¡¡their¡¡shoulders¡£¡±¡¡



Writing¡¡the¡¡Tests¡¡Before¡¡Writing¡¡the¡¡Code¡¡



The¡¡reason¡¡the¡¡previous¡¡solutions¡¡failed¡¡is¡¡because¡¡each¡¡solution¡¡was¡¡a¡¡knee¡­jerk¡¡reaction¡£¡¡¡¡

Knee¡­jerk¡¡reactions¡¡are¡¡those¡¡where¡¡when¡¡you¡¡encounter¡¡a¡¡bug£»¡¡you¡¡fix¡¡the¡¡bug¡ªno¡¡more¡¡and¡¡¡¡

no¡¡less¡£¡¡Instead£»¡¡you¡¡should¡¡figure¡¡out¡¡what¡¡the¡¡bug¡¡is¡¡trying¡¡to¡¡tell¡¡you¡£¡¡The¡¡original¡¡bug¡¡with¡¡¡¡

the¡¡leading¡¡whitespace¡¡was¡¡not¡¡a¡¡whitespace¡¡bug£»¡¡but¡¡a¡¡bug¡¡that¡¡was¡¡saying£»¡¡¡°Hey£»¡¡what¡¡if¡¡my¡¡¡¡

text¡¡is¡¡not¡¡aligned£»¡¡or¡¡part¡¡of¡¡a¡¡sentence£»¡¡and¡¡so¡¡on£¿¡±¡¡

¡¡¡¡¡¡¡¡¡¡¡¡To¡¡solve¡¡the¡¡bug£»¡¡you¡¡don¡¯t¡¡write¡¡code£»¡¡but¡¡you¡¡think¡¡of¡¡all¡¡of¡¡the¡¡tests¡¡that¡¡your¡¡code¡¡needs¡¡¡¡

to¡¡pass¡£¡¡You¡¡need¡¡to¡¡assign¡¡responsibility¡¡and¡¡define¡¡contexts¡¡that¡¡succeed¡¡and¡¡fail¡£¡¡In¡¡the¡¡¡¡

translation¡¡example£»¡¡the¡¡appropriate¡¡implementation¡¡approach¡¡would¡¡be¡¡to¡¡write¡¡the¡¡tests¡¡¡¡

before¡¡writing¡¡the¡¡code¡£¡¡Table¡¡3¡­1¡¡shows¡¡the¡¡contexts¡¡that¡¡fail¡¡and¡¡succeed¡£¡¡



Table¡¡3¡­1¡£¡¡Appropriate¡¡Tests¡¡for¡¡the¡¡Translation¡¡Program¡¡



Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¨¡¡allo¡¡¡¨¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



word¡¡allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡you¡¡can¡¯t¡¡translate¡¡a¡¡single¡¡word¡¡without¡¡translating¡¡the¡¡other¡¡words¡¡



word¡¡allo¡¡word¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡same¡¡reason¡¡as¡¡with¡¡word¡¡allo¡¡



prefixallo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡86¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

64¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡3¡­1¡£¡¡Appropriate¡¡Tests¡¡for¡¡the¡¡Translation¡¡Program¡¡£¨Continued£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡alloappend¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡prefixalloappend¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¡can¡¡see¡¡in¡¡the¡¡table£»¡¡most¡¡test¡¡cases¡¡are¡¡failures¡¡because¡¡the¡¡translation¡¡ponent¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡meant¡¡to¡¡translate¡¡single¡¡words¡¡only¡£¡¡The¡¡test¡¡cases¡¡seem¡¡plete£»¡¡but¡¡in¡¡fact£»¡¡we¡¡are¡¡missing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡one¡¡more¡¡set¡¡of¡¡cases£»¡¡which¡¡are¡¡outlined¡¡in¡¡Table¡¡3¡­2¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡3¡­2¡£¡¡¡¡The¡¡Missing¡¡Test¡¡Cases¡¡for¡¡the¡¡Translation¡¡Program¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡allO¡¡¡¨¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Text¡¡can¡¡contain¡¡mixed¡¡cases£»¡¡and¡¡from¡¡a¡¡human¡¡perspective£»¡¡mixed¡¡case¡¡is¡¡still¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡word¡£¡¡However£»¡¡the¡¡puter¡¡considers¡¡mixed¡¡case¡¡as¡¡a¡¡pletely¡¡different¡¡buffer£»¡¡and¡¡so¡¡we¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡must¡¡be¡¡able¡¡to¡¡cope¡¡with¡¡this¡¡situation¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­9¡¡shows¡¡the¡¡working¡¡solution¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Chaining¡¡ToLower£¨£©¡¡and¡¡

¡¡

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨2£© ²È£¨2£©

Äã¿ÉÄÜϲ»¶µÄ