軟件測試ST03_Logic_Coverage_第1頁
軟件測試ST03_Logic_Coverage_第2頁
軟件測試ST03_Logic_Coverage_第3頁
軟件測試ST03_Logic_Coverage_第4頁
軟件測試ST03_Logic_Coverage_第5頁
已閱讀5頁,還剩166頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、軟件測試與質(zhì)量保證申明:本課件是在原書作者課件基礎(chǔ)上編制,僅用于課堂教學,不得用于任何商業(yè)目的的活動。1 LOGICAL COVERAGEChapter 3 邏輯覆蓋第3章OUTLINEOverview: Logic Predicates and ClausesLogical Expression Coverage CriteriaStructural Logical Coverage of ProgramsSpecification-Based Logic CoverageLogical Coverage of Finite State MachinesDisjunctive Normal

2、Form Criteria(Master Level)4大綱概覽:邏輯謂詞和子句邏輯表達式覆蓋標準程序結(jié)構(gòu)化邏輯覆蓋基于規(guī)約的邏輯覆蓋有限狀態(tài)機的邏輯覆蓋析取范式標準(碩士水平)5CH. 3 : LOGIC COVERAGEApplied toApplied toApplied to6第三章: 邏輯覆蓋應(yīng)用于應(yīng)用于應(yīng)用于7COVERING LOGIC EXPRESSIONSLogic expressions show up in many situationsCovering logic expressions is required by the US Federal Aviation Ad

3、ministration for safety critical softwareLogical expressions can come from many sourcesDecisions in programsFSMs and statechartsRequirementsTests are intended to choose some subset of the total number of truth assignments to the expressions8覆蓋邏輯表達式 邏輯表達式出現(xiàn)在許多情況下 美國聯(lián)邦航空管理局的安全性至關(guān)重要的軟件標準要求覆蓋邏輯表達式 邏輯表達式

4、可以有多種來源決策程序FSMs和狀態(tài)圖需求 測試的目的是選擇事實總數(shù)中的一些子集分配到表達式9LOGIC PREDICATES AND CLAUSESA predicate is an expression that evaluates to a boolean valuePredicates can containboolean variablesnon-boolean variables that contain , =, 、 =、 =、! =布爾函數(shù)調(diào)用內(nèi)部結(jié)構(gòu)是由邏輯運算符構(gòu)建 取反操作符 和操作符 或操作符 蘊涵操作符 異或操作符 等價操作符子句是不含任何邏輯操作符的謂詞11EXAM

5、PLES(a = n*o)Four clauses:(a = n*o) relational expressionMost predicates have few clausesIt would be nice to quantify that claim!Sources of predicatesDecisions in programsGuards in finite state machinesDecisions in UML activity graphsRequirements, both formal and informalSQL queries12示例(a = n*o)四個子句

6、:(a = n*o) 關(guān)系表達式大多數(shù)謂詞有一些子句這將是很好進行量化該索賠!來源于謂詞程序中的決策有限狀態(tài)機中的監(jiān)護條件在UML活動圖中的決策分支需求,包括正式的和非正式的SQL查詢13Humans have trouble translating from English to LogicTRANSLATING FROM ENGLISH“I am interested in SWE 637 and CS 652”course = swe637 OR course = cs652“If you leave before 6:30 AM, take Braddock to 495, if yo

7、u leave after 7:00 AM, take Prosperity to 50, then 50 to 495”time 7:00 path = ProsperityHmm this is incomplete !time = 6:30 path = Prosperity14從語言到邏輯人類的從語言到邏輯人類的翻譯有問題翻譯有問題從英語翻譯“我對SWE 637 和 CS 652 有興趣”course = swe637 OR course = cs652“如果你6:30離開之前,走向Braddock 495,如果你上午7點離開,達到Prosperity50,然后從50到495”time

8、 7:00 path = Prosperity嗯這是不完整的!time = 6:30 path = Prosperity15OUTLINEOverview: Logic Predicates and ClausesLogical Expression Coverage CriteriaStructural Logical Coverage of ProgramsSpecification-Based Logic CoverageLogical Coverage of Finite State MachinesDisjunctive Normal Form Criteria(Master Lev

9、el)16大綱概覽:邏輯謂詞和子句邏輯表達式覆蓋標準程序結(jié)構(gòu)化邏輯覆蓋基于規(guī)約的邏輯覆蓋有限狀態(tài)機的邏輯覆蓋析取范式標準(碩士水平)17TESTING AND COVERING PREDICATES(3.2)We use predicates in testing as follows :Developing a model of the software as one or more predicatesRequiring tests to satisfy some combination of clausesAbbreviations:P is the set of predicatesp

10、 is a single predicate in PC is the set of clauses in PCp is the set of clauses in predicate pc is a single clause in C18測試和覆蓋謂詞(3.2) 我們在測試中使用謂詞如下:開發(fā)一個l軟件模型作為一個或多個謂詞需要測試滿足一些組合的子句 縮寫:P 是謂詞集合p 是P中一個獨立的詞C 是P 中的子句集Cp 是謂詞p中的子句c 是 C 中的獨立子句19PREDICATE AND CLAUSE COVERAGEThe first (and simplest) two criteri

11、a require that each predicate and each clause be evaluated to both true and falseWhen predicates come from conditions on edges, this is equivalent to edge coveragePC does not evaluate all the clauses, so 20謂詞和子句覆蓋 首先(也是最簡單的)兩個標準需求是每個謂詞和每個子句都被評估為true和false 當謂詞來自邊上的條件,這相當于邊覆蓋 謂詞覆蓋對不所有子句賦值,所以21PREDICAT

12、E COVERAGE EXAMPLE(a = n*o)predicate coveragePredicate = truea = 5, b = 10, D = true, m = 1, n = 1, o = 1= (5 = 1*1)= true true TRUE= truePredicate = falsea = 10, b = 5, D = false, m = 1, n = 1, o = 1= (10 = 1*1)= false false TRUE= false22謂詞覆蓋示例(a = n*o)謂詞覆蓋謂語謂語= truea = 5, b = 10, D = true, m = 1,

13、n = 1, o = 1= (5 = 1*1)= true true TRUE= true謂詞謂詞 = falsea = 10, b = 5, D = false, m = 1, n = 1, o = 1= (10 = 1*1)= false false TRUE= false23CLAUSE COVERAGE EXAMPLE(a = n*o)Clause coverageTwo tests(a b) = truea = 5, b = 10(a = n*o = truem = 1, n = 1, o = 1m = n*o = falsem = 1, n = 2, o = 2true cases

14、1) a = 5, b = 10, D = true, m = 1, n = 1, o = 1false cases2) a = 10, b = 5, D = false, m = 1, n = 2, o = 224子句覆蓋示例(a = n*o)子句覆蓋兩個測試(a b) = truea = 5, b = 10(a = n*o = truem = 1, n = 1, o = 1m = n*o = falsem = 1, n = 2, o = 2真的情形1) a = 5, b = 10, D = true, m = 1, n = 1, o = 1假的情形2) a = 10, b = 5, D =

15、 false, m = 1, n = 2, o = 225PROBLEMS WITH PC AND CC PC does not fully exercise all the clauses, especially in the presence of short circuit evaluation CC does not always ensure PCThat is, we can satisfy CC without causing the predicate to be both true and falseThis is definitely not what we want !

16、The simplest solution is to test all combinations 26謂詞覆蓋PC和子句覆蓋CC的問題 謂詞覆蓋沒有充分執(zhí)行所有的子句,尤其是在存在短路徑賦值 子句覆蓋不能總是確保謂詞覆蓋也就是說,我們可以滿足子句覆蓋不會導(dǎo)致謂詞是true和false這絕對不是我們想要的東西! 最簡單的解決方案是測試所有組合27COMBINATORIAL COVERAGECoC requires every possible combinationSometimes called Multiple Condition Coveragea = n*o(a = n*o)1TTTT

17、2TTFF3TFTT4TFFF5FTTT6FTFF7FFTF8FFFF28組合覆蓋組合覆蓋要求每一個可能的組合有時稱為多條件覆蓋a = n*o(a = n*o)1TTTT2TTFF3TFTT4TFFF5FTTT6FTFF7FFTF8FFFF29COMBINATORIAL COVERAGEThis is simple, neat, clean, and comprehensive But quite expensive!2N tests, where N is the number of clauses Impractical for predicates with more than 3 or

18、 4 clausesThe literature has lots of suggestions some confusingThe general idea is simple:Test each clause independently from the other clausesGetting the details right is hardWhat exactly does “independently” mean ?The book presents this idea as “making clauses active” 30組合覆蓋 這是簡單的,整潔、干凈、全面的但是很昂貴!2

19、N 測試中 N 是子句的數(shù)量不現(xiàn)實的謂詞超過3或4子句文獻有很多建議有些令人困惑一般的想法很簡單:獨立于其他的子句測試每個子句獲得細節(jié)信息的權(quán)力是很困難的“獨立”到底是什么意思?這本書介紹了這個想法即“使子句有效”31ACTIVE CLAUSESClause coverage has a weakness : The values do not always make a differenceConsider the first test for clause coverage, which caused each clause to be true:(5 = 1*1)Only the fir

20、st clause counts !To really test the results of a clause, the clause should be the determining factor in the value of the predicateDetermination :A clause ci in predicate p, called the major clause, determines p if and only if the values of the remaining minor clauses cj are such that changing ci ch

21、anges the value of pThis is considered to make the clause active32有效子句 子句覆蓋有一個缺點:值并不總是產(chǎn)生影響 考慮第一次對子句覆蓋測試,它導(dǎo)致每個子句是ture:(5 = 1*1) 只有第一個子句計數(shù)! 要真正測試子句的結(jié)果,該子句應(yīng)該謂詞值中的決定因素決定 :一個子句ci在謂詞p中,稱為主要子句,它決定了p,當且僅當余下的較小子句cj是這樣的,即改變ci將改變P的值。這是被認為有效子句33DETERMINING PREDICATESGoal : Find tests for each clause when the cl

22、ause determines the value of the predicateThis is formalized in several criteria that have subtle, but very important, differencesP = A Bif B = true, p is always true.so if B = false, A determines p.if A = false, B determines p.P = A Bif B = false, p is always false.so if B = true, A determines p.if

23、 A = true, B determines p.34決定謂詞 目標:找到每個子句的測試,當子句決定謂詞的值 這是若干標準的正式形式,有細微的差異,但是很重要P = A B如果B = true, p總是真。所以,如果B = false, A決定p。如果A= false, B決定p。P = A B如果B = false, p總是假。所以,如果B = true,A決定p。如果A= true,B決定p。35p = a b1)a = true, b = false2)a = false, b = false3)a = false, b = true4)a = false, b = falseACTI

24、VE CLAUSE COVERAGEThis is a form of MCDC, which is required by the FAA for safety critical softwareAmbiguity : Do the minor clauses have to have the same values when the major clause is true and false?Duplicatea is major clauseb is major clause36p = a b1)a = true, b = false2)a = false, b = false3)a

25、= false, b = true4)a = false, b = false有效子句覆蓋這是一種MCDC(主句決定子句),這是由美國聯(lián)邦航空局對安全關(guān)鍵軟件的要求歧義:當主要子句是真和假,余下子句必須有相同的值?副本副本a 是主子句是主子句b 是主子句是主子句37RESOLVING THE AMBIGUITYThis question caused confusion among testers for yearsConsidering this carefully leads to three separate criteria :Minor clauses do not need to

26、be the sameMinor clauses do need to be the sameMinor clauses force the predicate to become both true and falsep = a (b c)Major clause : aa = true, b = false, c = truea = false, b = false, c = falsec = falseIs this allowed ?38解決歧義 這個問題在測試人員當中多年來引起混亂 仔細考慮導(dǎo)致三個獨立的標準:次子句不需要做得相同次子句必須做的相同次子句使得謂詞變?yōu)榧鎮(zhèn)鋞rue和fa

27、lsep = a (b c)主子句主子句: aa = true, b = false, c = truea = false, b = false, c = falsec = false這允許嗎?39GENERAL ACTIVE CLAUSE COVERAGEThis is complicated !It is possible to satisfy GACC without satisfying predicate coverageWe really want to cause predicates to be both true and false !40廣義有效的子句覆蓋 這是復(fù)雜的! 它

28、可以滿足GACC卻沒有滿足謂詞覆蓋 我們真的想引起謂詞是真和假!41RESTRICTED ACTIVE CLAUSE COVERAGEThis has been a common interpretation by aviation developersRACC often leads to infeasible test requirementsThere is no logical reason for such a restriction42限制性有效子句覆蓋 這是一個航空開發(fā)常見的解釋 RACC往往導(dǎo)致不可行的測試要求 有這樣的限制是不合乎邏輯的理由43CORRELATED ACTIV

29、E CLAUSE COVERAGEA more recent interpretationImplicitly allows minor clauses to have different valuesExplicitly satisfies (subsumes) predicate coverage44相關(guān)有效子句覆蓋 最近的一個解釋 隱式地允許次子句有不同的值 顯式地滿足(涵括)謂詞覆蓋45CACC AND RACCabca (b c)1TTTT2TTFT3TFTT4TFFF5FTTF6FTFF7FFTF8FFFFTTTTFFFFamajor clausePa : b=true or c

30、= trueCACC can be satisfied by choosing any of rows 1, 2, 3 AND any of rows 5, 6, 7 a total of nine pairsabca (b c)1TTTT2TTFT3TFTT4TFFF5FTTF6FTFF7FFTF8FFFFTTTTFFFFaRACC can only be satisfied by row pairs (1, 5), (2, 6), or (3, 7)Only three pairs46相關(guān)有效子句覆蓋和限制性有效子句覆蓋abca (b c)1TTTT2TTFT3TFTT4TFFF5FTTF

31、6FTFF7FFTF8FFFFTTTTFFFFa主句主句Pa : b=true or c = trueCACC可以滿足選擇1、2、3任何的行和5、6、7任何行-總共九對abca (b c)1TTTT2TTFT3TFTT4TFFF5FTTF6FTFF7FFTF8FFFFTTTTFFFFaRACC只能滿足行對(1、5),(2、6),或(3、7)只有三個對47INACTIVE CLAUSE COVERAGE The active clause coverage criteria ensure that “major” clauses do affect the predicates Inactive

32、 clause coverage takes the opposite approach major clauses do not affect the predicates48無效子句覆蓋 有效子句覆蓋標準確?!爸鳌弊泳鋾绊懼^詞 無效子句覆蓋卻反其道而行之主子句不影響謂詞49GENERAL AND RESTRICTED ICC Unlike ACC, the notion of correlation is not relevantci does not determine p, so cannot correlate with p Predicate coverage is always

33、 guaranteed50廣義 和 限制性 無效子句覆蓋 與ACC不同的是,相關(guān)的概念是不相關(guān)的 ci不決定p,所以不能決定p 可行性方面,謂詞覆蓋總是可得到滿足51LOGIC COVERAGE CRITERIA SUBSUMPTION Clause CoverageCCPredicate CoveragePCCombinatorial Clause CoverageCOCRestricted Active Clause CoverageRACCRestricted Inactive Clause CoverageRICCGeneral Active Clause CoverageGACCCo

34、rrelated Active Clause CoverageCACCGeneral Inactive Clause CoverageGICC52邏輯覆蓋標準包含關(guān)系子句覆蓋CC謂詞覆蓋PC完全子句覆蓋COC限制性有效子句覆蓋RACC限制性無效子句覆蓋RICC廣義有效子句覆蓋GACC相關(guān)有效子句覆蓋CACC廣義無效子句覆蓋GICC53MAKING CLAUSES DETERMINE A PREDICATEFinding values for minor clauses cj is easy for simple predicatesBut how to find values for more

35、 complicated predicates ?Definitional approach: pc=true is predicate p with every occurrence of c replaced by true pc=false is predicate p with every occurrence of c replaced by falseTo find values for the minor clauses, connect pc=true and pc=falsewith exclusive ORpc = pc=true pc=falseAfter solving

36、, pcdescribes exactly the values needed for c to determine p54使子句決定謂詞 尋找次子句 cj 的值,對簡單謂詞是容易的 但是如何找到更多的復(fù)雜謂詞的值? 定義方法: pc=true 代表謂詞 p 中 c 的每次出現(xiàn)都由 true 來代替 pc=false 代表謂詞 p 中 c 的每次出現(xiàn)都由 false 來代替 尋找次子句的值, 用異或連接 pc=true 和 pc=falsepc = pc=true pc=false 結(jié)果是, pc 描述了 c 的取值決定p值的具體條件55EXAMPLESp = a bpa = pa=true

37、pa=false = (true b) XOR (false b) = true XOR b = bp = a bpa = pa=true pa=false = (true b) (false b) = b false = bp = a (b c)pa = pa=true pa=false = (true (b c) (false (b c) = true (b c) = (b c) = b c “NOT b NOT c” means either b or c can be false RACC requires the same choice for both values of a, C

38、ACC does not56示例p = a bpa = pa=true pa=false = (true b) (false b) = true b = bp = a bpa = pa=true pa=false = (true b) (false b) = b false = bp = a (b c)pa = pa=true pa=false = (true (b c) (false (b c) = true (b c) = (b c) = b c “NOT b NOT c”意味著b或c可以為假RACC需要對兩個a值做相同選擇,CACC卻不是57REPEATED VARIABLES The

39、definitions in this chapter yield the same tests no matter how the predicate is expressed (a b) (c b) = (a c) b (a b) (b c) (a c)Only has 8 possible tests, not 64 Use the simplest form of the predicate, and ignore contradictory truth table assignments58重復(fù)變量 無論謂詞怎樣表示,本章中的定義都產(chǎn)生了相同的測試 (a b) (c b) = (a

40、c) b (a b) (b c) (a c)只有8個可能的測試,而不是64個 使用最簡單的形式的謂詞,并忽視矛盾復(fù)雜的賦值表59A MORE SUBTLE EXAMPLEp = ( a b ) ( a b)pa = pa=true pa=false = (true b) (true b) (false b) (false b) = (b b) false = true false = true a always determines the value of this predicate b never determines the value b is irrelevant !p = ( a

41、 b ) ( a b)pb = pb=true pb=false = (a true) (a true) (a false) (a false) = (a false) (false a) = a a = false60一個更微妙的例子p = ( a b ) ( a b)pa = pa=true pa=false = (true b) (true b) (false b) (false b) = (b b) false = true false = truea總是決定這個謂詞的值b從來沒有決定值- b是不相關(guān)的!p = ( a b ) ( a b)pb = pb=true pb=false =

42、 (a true) (a true) (a false) (a false) = (a false) (false a) = a a = false61INFEASIBLE TEST REQUIREMENTSConsider the predicate:(a b b c) c a(a b) = true, (b c) = true, (c a) = true is infeasibleAs with graph-based criteria, infeasible test requirements have to be recognized and ignoredRecognizing in

43、feasible test requirements is hard, and in general, undecidableSoftware testing is inexact engineering, not science62不可行的測試需求 考慮謂詞:(a b b c) c a(a b) = true, (b c) = true, (c a) = true是不可行的 作為圖形為基礎(chǔ)的標準,不可行的測試需求必須得到承認和忽略 認識不可行的測試需求是很難的,在一般情況下,不可判定的 軟件測試是不準確的工程,而不是科學63LOGIC COVERAGE SUMMARYPredicates a

44、re often very simplein practice, most have less than 3 clausesIn fact, most predicates only have one clause !With only clause, PC is enoughWith 2 or 3 clauses, CoC is practicalAdvantages of ACC and ICC criteria significant for large predicates CoC is impractical for predicates with many clausesContr

45、ol software often has many complicated predicates, with lots of clausesQuestion why dont complexity metrics count the number of clauses in predicates?64邏輯覆蓋總結(jié) 在實踐中謂詞通常很簡單的,大多數(shù)少于3個子句事實上,大多數(shù)謂詞只有一個子句!只有子句,謂詞覆蓋(PC)就夠了2或3子句,組合覆蓋(CoC)是實用的對于大型謂詞有效子句覆蓋(ACC)和無效子句覆蓋(ICC)標準的優(yōu)勢顯著對很多子句,組合覆蓋(CoC)是不切實際 控制軟件通常有許多復(fù)雜

46、的謂詞,有大量的子句 問題為什么不能對謂詞中子句的數(shù)目進行度量復(fù)雜性計數(shù)?65OUTLINEOverview: Logic Predicates and ClausesLogical Expression Coverage CriteriaStructural Logical Coverage of ProgramsSpecification-Based Logic CoverageLogical Coverage of Finite State MachinesDisjunctive Normal Form Criteria(Master Level)66大綱概覽:邏輯謂詞和子句邏輯表達式覆

47、蓋標準程序結(jié)構(gòu)化邏輯覆蓋基于規(guī)約的邏輯覆蓋有限狀態(tài)機的邏輯覆蓋析取范式標準(碩士水平)67LOGIC EXPRESSIONS FROM SOURCEPredicates are derived from decision statements in programsIn programs, most predicates have less than four clausesWise programmers actively strive to keep predicates simpleWhen a predicate only has one clause, COC, ACC, ICC,

48、and CC all collapse to predicate coverage (PC)Applying logic criteria to program source is hard because of reachability and controllability:Reachability : Before applying the criteria on a predicate at a particular statement, we have to get to that statementControllability : We have to find input va

49、lues that indirectly assign values to the variables in the predicatesVariables in the predicates that are not inputs to the program are called internal variablesThese issues are illustrated through an example in the following slides 68源程序邏輯表達式謂詞是程序判斷語句的推斷在程序中,大多數(shù)謂詞少于四個子句聰明的程序員的積極努力保持謂詞簡單當一個謂詞只有一個子句,

50、組合覆蓋CoC、有效子句覆蓋ACC、無效子句覆蓋ICC和子句覆蓋CC對謂詞覆蓋(PC)全部失效對程序源代碼使用邏輯標準的是很難的,因為可達性和可控性:可達性:在一個特定語句的謂詞上應(yīng)用覆蓋標準,我們必須得到該語句可控性:我們必須找到間接指定值到謂詞變量的輸入值在謂詞中不是輸入到程序的變量,被稱為內(nèi)部變量我們來通過例子來理解這些概念.69TRIANG (PG 1 OF 5) 1 / Jeff Offutt - Java version Feb 2003 2 / The old standby: classify triangles 3 / Figures 3.2 and 3.3 in the b

51、ook. 4 import java.io.*; 5 class trityp 6 7 private static String triTypes = , / Ignore 0. 8 scalene, isosceles, equilateral, not a valid triangle; 9 private static String instructions = This is the ancient TriTyp program.nEnter three integers that represent the lengths of the sides of a triangle.nT

52、he triangle will be categorized as either scalene, isosceles, equilateralnor invalid.n; 10 11 public static void main (String argv) 12 / Driver program for trityp 13 int A, B, C; 14 int T;70三角形(頁 1 / 5) 1 / Jeff Offutt - Java version Feb 2003 2 / 舊的備用舊的備用: 三角形分類三角形分類 3 / 教材圖教材圖 3.2 和圖和圖3.3. 4 import

53、 java.io.*; 5 class trityp 6 7 private static String triTypes = “”, / 忽略忽略 0. 8 scalene, isosceles, equilateral, not a valid triangle; 9 private static String instructions = “這是古老的三角形程序這是古老的三角形程序.n 輸入三個整數(shù)各表示三角形的一條邊輸入三個整數(shù)各表示三角形的一條邊.n 三角形將三角形將 被分為不等邊、等腰、被分為不等邊、等腰、等邊等邊n 或或不是三角形不是三角形.n; 10 11 public sta

54、tic void main (String argv) 12 / Driver program for trityp 13 int A, B, C; 14 int T;71TRIANG (PG 2 OF 5) 16 System.out.println (instructions); 17 System.out.println (Enter side 1: ); 18 A = getN(); 19 System.out.println (Enter side 2: ); 20 B = getN(); 21 System.out.println (Enter side 3: ); 22 C =

55、getN(); 23 T = Triang (A, B, C); 24 25 System.out.println (Result is: + triTypes T); 26 27 28 / =72三角形(頁 2 / 5) 16 System.out.println (instructions); 17 System.out.println (“輸入邊輸入邊1: ); 18 A = getN(); 19 System.out.println (輸入邊輸入邊2: ); 20 B = getN(); 21 System.out.println (輸入邊輸入邊3: ); 22 C = getN();

56、 23 T = Triang (A, B, C); 24 25 System.out.println (“結(jié)果是結(jié)果是: + triTypes T); 26 27 28 / =73TRIANG (PG 3 OF 5) 29 / The main triangle classification method 30 private static int Triang (int Side1, int Side2, int Side3) 31 32 int tri_out; 33 34 / tri_out is output from the routine: 35 / Triang = 1 if t

57、riangle is scalene 36 / Triang = 2 if triangle is isosceles 37 / Triang = 3 if triangle is equilateral 38 / Triang = 4 if not a triangle 39 40 / After a quick confirmation that its a legal 41 / triangle, detect any sides of equal length 42 if (Side1 = 0 | Side2 = 0 | Side3 = 0) 43 44 tri_out = 4; 45

58、 return (tri_out); 46 74三角形(頁 3 / 5) 29 / 三角形分類的主方法三角形分類的主方法 30 private static int Triang (int Side1, int Side2, int Side3) 31 32 int tri_out; 33 34 / tri_out 的輸出規(guī)則的輸出規(guī)則: 35 / Triang = 1 如果三角形是不等邊的如果三角形是不等邊的 36 / Triang = 2 如果如果三角形三角形是等腰的是等腰的 37 / Triang = 3 如果如果三角形三角形是是等邊的是是等邊的 38 / Triang = 4 如果不是

59、三角形如果不是三角形 39 40 /快速確認,這是一個合法的三角形后快速確認,這是一個合法的三角形后, 41 /檢測任何等長的檢測任何等長的邊邊 42 if (Side1 = 0 | Side2 = 0 | Side3 = 0) 43 44 tri_out = 4; 45 return (tri_out); 46 75TRIANG (PG 4 OF 5) 48 tri_out = 0; 49 if (Side1 = Side2) 50 tri_out = tri_out + 1; 51 if (Side1 = Side3) 52 tri_out = tri_out + 2; 53 if (Si

60、de2 = Side3) 54 tri_out = tri_out + 3; 55 if (tri_out = 0) 56 / Confirm its a legal triangle before declaring 57 / it to be scalene 58 59 if (Side1+Side2 = Side3 | Side2+Side3 = Side1 | 60 Side1+Side3 = Side2) 61 tri_out = 4; 62 else 63 tri_out = 1; 64 return (tri_out); 65 76三角形(頁 4 / 5) 48 tri_out = 0; 49 if (Side1 = Side2) 50 tri_out = tri_out + 1; 51 if (Side1 = Side3) 52 tri_out = tri_out + 2; 53 if (Side2 = Side3) 54 tri

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。