From 9010a430bed7ccbaf573f13192f49b434ded27de Mon Sep 17 00:00:00 2001 From: PersnicketyChkn Date: Wed, 29 Apr 2026 11:41:03 -0700 Subject: [PATCH] completed testing --- .Guesser.cpp.swp | Bin 0 -> 12288 bytes .GuesserTest.cpp.swp | Bin 0 -> 12288 bytes Guesser.cpp.gcov | 154 +++++++++++++++++++++++++++++++++++++++++++ GuesserTest.cpp | 89 +++++++++++++++++++++++-- 4 files changed, 238 insertions(+), 5 deletions(-) create mode 100644 .Guesser.cpp.swp create mode 100644 .GuesserTest.cpp.swp create mode 100644 Guesser.cpp.gcov diff --git a/.Guesser.cpp.swp b/.Guesser.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..017067049ef566f305691d0b71abc06279c55d33 GIT binary patch literal 12288 zcmeHNO^6&t6t4Ie|Kh)R5aA_CGLxO1%G2 zNK8EBV8C1yJc$OU4hqqLUf<~Q~ms|5MSIZgde6VCm-A zPZ@>V_U1CnWLmzr{qgu(r`(=nz%g)r7}y}@=eix%_4uZZ^xy+8TpzVgi(|ks;23ZW zI0hU8jseGjW56+RLolGn>%?hzdQ;);%fK_*b{UdHnx>`S<^?_X_bn@C|Sg_#F5QxBw{NQQ+Hqgg68A zfIl_}@gZ;ocoNtStOtI-TZpfLbHG{PC14})81TbgLVOCm54;Dw11Mk*@HDU$XaHM) zCx9RCgbc6*JOVrf{B?&A-vJkZPk{5lIp8di1AX8XU>P_HJPcgA9lin@*aG~$UWku@ z)4)mKC~!Y;@irk&0o#FJZiNi+5pV`r2KEC>Koj@}{QU%60=@#i1kM8=0B-|t0dE2c za13C+L%_Wp1OE#K-Vj6#qEzZUjY+4uT*QKmGI;{;t2PH7R(ZEvCmJoMa^$I4#lzWI zyHy^o3q^^4Oa|1e^b@H;g90@e$W+F@q@6TJO}0ps$C(<&5LdCTi}dgz(;lQ7L;ki> zlkKrJqsuJO#vWYCq>t-ZbyvOs8?U)eJE%)1PhzQX6rS{xB%v~e6O9`)6*x*Kkd z6=R}h&RPS>03j-vw!1Q;EKKq!piHYMg056%xHgRIFqM)T^UXFb4eAc4tT0W3Bqc9C zP6^yganj3@xJ6m+hwN00AQV&-uH&Tf31OKi9l}LU6*9b7KkarlbrXtMG|9EG)R)ZN z<>#gb3RY-eGLb7XZP6r@G5-cl)s;Yaj3c>LE3zV@vSS@8uFWKrUU?}y8%U_yRfd(4 z{;Sf5cTto~5W6wB!#@6%iH2zD2?wl*2rd%T_~ZZ{f)NgJd8E;#K_2^B!A-+*HkQ5` zDBrV7sT_J~z*GcM%XDOF$7p~u`zlq@5OIMFb`g;|8l=gnX5Gj)o@tt;(x%bsYvfs) zYsn7yvc*}Z;(&cX{QAeM>zD-Ptn{q1T}BzGV!GmF8p|n<%#{ovJ_(f{Qs|Ax5;s)? zk_a}OZ6LGyNUP=oGdT`ZFO%(QOqr|7Su_+j!mS5naeHA!EV4E$TF|wpAPkw$aVXCr zON?PYHcpcjR9;~Hwb=misYbDFs}S52>gC^~dF~}u`S+|Zyk`4H)l+(fV`b|(adnY) zmiN&x8l4u+&zWAuUB}+59m#m8L*&X%Y;vdCYrlWFuu%L`_8Kb>0n=XZViPKxShcGcF+iZ10Au-6#$C>}#k`r;o+#6>)fO>(${<$cvmnQ$F1GV>vHBpf z=|J@(Gc&BmYN||lx}lmpjZFV(+mDDMaYZ(Gu&G{WkrXCRb;i1ZoY=hCY}ljaDuicd z>aNtip1H#9Xtpq3X@K?B1G=hqVA(F45{BIB*^DMNr5$}{%#TMgS_pF$=cB&i>R>T^5VuK~MCHy@o+mY* zsFJCCB;ZAp3oX-&@{A=j9V{$Zx)$+$UZg^l<3VtT5AVaBwFN6vTiH}3cstxA{sqe= BC+PqH literal 0 HcmV?d00001 diff --git a/.GuesserTest.cpp.swp b/.GuesserTest.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..9cd90742cf7a1cbcfac8c65659d8acff54956759 GIT binary patch literal 12288 zcmeI2Piz!b9LIn7mjS5)Azq)Whuuxt-Ifr;0wyhOX>BQOcMIyl&Ft*!?xfq9&CFX! zZ3;04(U^GAqZ&OJFQO(IJs1Mv#Erygz&{6w2SW%UfnZF)Ki@YyL$`EhDNBMhd6RrP z*`1l+@BKdW<~OtH6f^sV_ONZKF2eE@(Y4X5=7sl&K7548s5qu8zrVvW(leIdJGOb( z;KWd_)vkxUfa%?J?z-Fw)_LxVlu@g-I#O*@29$w&H?WSjba!QBoM&Utu#Fog?>(f7 zpbRJj%78MU3@8K2fHI&AC<80TfT*pa!x-&D{)oB1UUl2r|EN~VfHI&ACsz?(_j<$`w5~O;CFBm zd=k}5e$L>kOCdx`Wn3V0DcB%!3ppYI0D`P zCb*~(od#cmW8fXI7F=FU^dtBId<8OKJ^1HwqD$Z$I024>cR>fZ@)*%i;Ct{1cniD< zrokUL52wKw;C=8K(1AQZuL89w1IoaPF)&ZeUwU%6{)v2{e?0DVvP@$8tql&_$;zo2 zT^N;ktS1(=rMLAKt!Ud-wkTHba9?g@ba+G_I2R1#KCS(CyjU3}_3rBHmt)BH=kjrX zgM8_$lO5D&3-;7hg6^B9p!^V9|F@=aMZ&fVGrBcf5RS>+f~at-VAzhs4bf7YwsD(# z@7e>q2Zvr99@#UxcWitjm!I6X|D~5-@%s5dlnvSJTO1Y^FzS5C)>pNya-_oUCWWCj z^xVBh+u`l!i;~h9$6Uyqtm5j9%-1|c!s?4k7bP@kCo-Y7NfNhpop6gDZeb9<0=H^*CZB)5#v3iZ^Q-V8;>qfn_l!6U;X1j<2DN+*-_ E9}qPE + -: 3:#include + -: 4: + -: 5:using std::string; + -: 6: + -: 7:/* + -: 8: Returns an whole number representing the distance between the guess, + -: 9: provided as an argument, and the secret. The distance represents the number + -: 10: of characters that would have to be changed at the same location to match + -: 11: the other string. When the two strings are identical, the distance is 0, + -: 12: but for each letter different, the distance increases by 1. When the + -: 13: strings are different lengths, each of the extra characters in the longer + -: 14: string also counts as an increase in 1 to the distance, up to the length of + -: 15: the secret; in other words, if m_secret has a 10 characters and the guess + -: 16: has 100, the distance is 10. + -: 17:*/ +function _ZN7Guesser8distanceENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE called 16 returned 100% blocks executed 100% + 16: 18:unsigned int Guesser::distance(string guess){ + 16: 19: int length_diff = 0; + 16: 20: if( guess.length() > m_secret.length() ){ +call 0 returned 16 +call 1 returned 16 +branch 2 taken 5 (fallthrough) +branch 3 taken 11 + 5: 21: length_diff += guess.length() - m_secret.length(); +call 0 returned 5 +call 1 returned 5 + -: 22: } + 11: 23: else if( guess.length() < m_secret.length() ){ +call 0 returned 11 +call 1 returned 11 +branch 2 taken 3 (fallthrough) +branch 3 taken 8 + 3: 24: length_diff += m_secret.length() - guess.length(); +call 0 returned 3 +call 1 returned 3 + -: 25: } + 65: 26: for(int i=0; i < m_secret.length() && i < guess.length(); i++ ){ +call 0 returned 65 +branch 1 taken 52 (fallthrough) +branch 2 taken 13 +call 3 returned 52 +branch 4 taken 49 (fallthrough) +branch 5 taken 3 +branch 6 taken 49 +branch 7 taken 16 (fallthrough) + 49: 27: if( m_secret.at(i) != guess.at(i) ){ +call 0 returned 49 +call 1 returned 49 +branch 2 taken 12 (fallthrough) +branch 3 taken 37 + 12: 28: length_diff++; + -: 29: } + -: 30: } + 16: 31: if( length_diff > m_secret.length() ){ +call 0 returned 16 +branch 1 taken 4 (fallthrough) +branch 2 taken 12 + 4: 32: length_diff = m_secret.length(); +call 0 returned 4 + -: 33: } + 16: 34: return length_diff; + -: 35:} + -: 36: + -: 37:/* + -: 38: Constructor requires that the secret phrase is provided its value as + -: 39: an argument. This secret will not change for the lifespan of an instance + -: 40: of any Guesser object and must have a length of 32 characters or less, + -: 41: otherwise, it will be truncated at that length. + -: 42:*/ +function _ZN7GuesserC2ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE called 13 returned 100% blocks executed 83% + 13: 43:Guesser::Guesser(string secret){ +call 0 returned 13 + 13: 44: if( secret.length() > 32 ){ +call 0 returned 13 +branch 1 taken 1 (fallthrough) +branch 2 taken 12 + 1: 45: m_secret = secret.substr(0, 32); +call 0 returned 1 +branch 1 taken 1 (fallthrough) +branch 2 taken 0 (throw) +call 3 returned 1 +call 4 returned 1 + -: 46: } + -: 47: else{ + 12: 48: m_secret = secret; +call 0 returned 12 +branch 1 taken 12 (fallthrough) +branch 2 taken 0 (throw) + -: 49: } + 13: 50: m_locked = false; + 13: 51: m_remaining = 3; + 13: 52:} +call 0 never executed + -: 53: + -: 54:/* + -: 55: Determines and returns whether the provided guess matches the secret + -: 56: phrase. However, the function also returns false if the secret is locked, + -: 57: which happens if either (or both): + -: 58: (A) there are no remaining guesses allowed + -: 59: (B) the function detects brute force, as indicated by a guess that has a + -: 60: distance greater than 2 from the secret + -: 61: See the distance() functions for specifications regarding determining the + -: 62: distance between a guess and the secret. + -: 63: + -: 64: A Guesser object allows up to + -: 65: three (3) consecutive guesses without a match. If three guesses are made + -: 66: without any being a true match, the secret is locked. However, whenever + -: 67: an unlocked secret is guessed with a true match, the guesses remaining + -: 68: reset to three (3). If the secret is locked for any other reason, such + -: 69: as a big distance in a guess, the count of remaining guesses should still + -: 70: count down as usual to hide that the secret has been locked. + -: 71:*/ +function _ZN7Guesser5matchENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE called 17 returned 100% blocks executed 88% + 17: 72:bool Guesser::match(string guess){ + 17: 73: if( m_remaining < 1 || m_locked ){ +branch 0 taken 15 (fallthrough) +branch 1 taken 2 +branch 2 taken 3 (fallthrough) +branch 3 taken 12 + 5: 74: return false; + -: 75: } + 12: 76: else if( guess != m_secret ){ +call 0 returned 12 +branch 1 taken 11 (fallthrough) +branch 2 taken 1 + 11: 77: unsigned int difference = distance(guess); +call 0 returned 11 +branch 1 taken 11 (fallthrough) +branch 2 taken 0 (throw) +call 3 returned 11 +branch 4 taken 11 (fallthrough) +branch 5 taken 0 (throw) +call 6 returned 11 +call 7 never executed + 11: 78: if( difference > 2 ){ +branch 0 taken 1 (fallthrough) +branch 1 taken 10 + 1: 79: m_locked = true; + -: 80: } + -: 81: else{ + 10: 82: m_remaining--; + -: 83: } + 11: 84: return false; + -: 85: } + -: 86: else{ + 1: 87: return true; + -: 88: } + -: 89:} diff --git a/GuesserTest.cpp b/GuesserTest.cpp index dce8eaa..d0db7d5 100644 --- a/GuesserTest.cpp +++ b/GuesserTest.cpp @@ -14,9 +14,88 @@ class GuesserTest : public ::testing::Test virtual void TearDown(){} //clean up after each test, (before destructor) }; -// Example "smoke test" (can be deleted) -TEST(GuesserTest, smoke_test) +// distance() tests +TEST(GuesserTest, distance) { - Guesser object("Secret"); - ASSERT_EQ( 1+1, 2 ); -} \ No newline at end of file + Guesser g("A"); + int r = g.distance("A"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, no_guess) +{ + Guesser g("A"); + int r = g.distance(""); + ASSERT_EQ(r, 1); +} +TEST(GuesserTest, less) +{ + Guesser g("AAA"); + int r = g.distance("A"); + ASSERT_EQ(r, 2); +} +TEST(GuesserTest, more) +{ + Guesser g("A"); + int r = g.distance("AAA"); + ASSERT_EQ(r, 2); +} +TEST(GuesserTest, too_long) +{ + Guesser g("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int r = g.distance("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF"); + ASSERT_EQ(r, 0); +} + +// match() tests +TEST(GuesserTest, match) +{ + Guesser g("A"); + bool r = g.match("A"); + ASSERT_EQ(r, 1); +} +TEST(GuesserTest, offBy1) +{ + Guesser g("A"); + bool r = g.match("AB"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, offBy2) +{ + Guesser g("A"); + bool r = g.match("ABC"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, offBy3) +{ Guesser g("A"); + bool r = g.match("BCD"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, no_guess_match) +{ Guesser g("A"); + bool r = g.match(""); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, too_many_tries) +{ Guesser g("A"); + bool r = g.match("B"); + r = g.match("B"); + r = g.match("B"); + r = g.match("B"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, too_many_tries_then_correct) +{ Guesser g("A"); + bool r = g.match("B"); + r = g.match("B"); + r = g.match("B"); + r = g.match("A"); + ASSERT_EQ(r, 0); +} +TEST(GuesserTest, way_off) +{ Guesser g("ABCDE"); + bool r = g.match("BKDSLNKL"); + r = g.match("B"); + r = g.match("B"); + r = g.match("A"); + ASSERT_EQ(r, 0); +}