SE Lab
0 0

13 مثالًا من تطبيقات حقيقية13 examples from real apps

الأبيض: اقرأ الكود والمخطط والمسارات. الأسود: اقرأ المواصفة والفئات والحدود. ثم افتح المثال في المختبر وجرّبه بنفسك.White: read the code, graph and paths. Black: read the spec, classes and boundaries. Then open it in the lab and try it yourself.

0 / 13
1

أرخص سعر في تطبيق مقارنة الأسعارCheapest price in a price-comparison app

التطبيق يجمع أسعار المنتج من عدة متاجر ويعرض الأرخص. هذا مثال المقرّر (أصغر عنصر في مصفوفة) بثوب حديث.The app collects a product’s price from several stores and shows the cheapest. This is the course example (min of an array) in modern clothes.

صندوق أبيض · White box ويب + جوال · Web + Mobile while if V(G)=3
function cheapestPrice(prices) {
  let min = prices[0];
  let i = 1;
  while (i < prices.length) {
    if (prices[i] < min) {
      min = prices[i];
    }
    i++;
  }
  return min;
}
V(G) P + 1 = 2 + 1 = 3 E − N + 2 = 7 − 6 + 2 = 3
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-6prices = [7]7
1-2-3-5-2-6prices = [4,9]4
1-2-3-4-5-2-6prices = [8,3]3
  • العقدة 1 تضم سطرين لأنهما متتاليان بلا تفرّع.Node 1 holds two lines because they run in a row with no branch.
  • المسار 1-2-6 يحتاج سعرًا واحدًا فقط: الحلقة لا تعمل أبدًا.Path 1-2-6 needs a single price: the loop never runs.

أي مدخل يمرّ بالعقدة 4؟Which input visits node 4?

2

متوسط تقييم المطعمA restaurant’s average rating

التطبيق يحسب متوسط النجوم (1–5) ويتجاهل القيم غير الصالحة، ويتوقف عند null (نهاية الصفحة المحمّلة). مثال المقرّر «average» مع الشروط المركّبة.The app averages star ratings (1–5), skips invalid values, and stops at null (end of the loaded page). The course “average” example with compound conditions.

صندوق أبيض · White box جوال · Mobile && while V(G)=6
function averageRating(ratings) {
  let i = 0, count = 0, sum = 0, avg;
  while ((i < ratings.length) && (ratings[i] !== null)) {
    if ((ratings[i] >= 1) && (ratings[i] <= 5)) {
      count++; sum += ratings[i];
    }
    i++;
  }
  if (count > 0) {
    avg = Math.round((sum / count) * 10) / 10;
  } else {
    avg = null;
  }
  return avg;
}
V(G) P + 1 = 5 + 1 = 6 E − N + 2 = 15 − 11 + 2 = 6
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-8-10-11ratings = []null
1-2-3-8-10-11ratings = [null]null
1-2-3-4-7-2-8-10-11ratings = [0]null
1-2-3-4-5-7-2-8-10-11ratings = [9]null
1-2-3-4-5-6-7-2-8-9-11ratings = [4]4
  • كل جزء من && عقدة مستقلّة: 2 و 3، ثم 4 و 5.Each side of && is its own node: 2 and 3, then 4 and 5.
  • V(G) = 6 حدّ أعلى: 5 مسارات هنا تغطي كل الأسهم الـ 15.V(G) = 6 is an upper bound: these 5 paths already cover all 15 edges.

كم عقدة قرار في هذا الكود؟How many decision nodes does this code have?

3

رسوم الشحن في متجر إلكترونيShipping fee in an online store

دولي: 25. محلي من 50 فأكثر: مجاني. عضو: 2. غير ذلك: 5.International: 25. Domestic from 50 up: free. Member: 2. Otherwise: 5.

صندوق أبيض · White box ويب · Web else if V(G)=4
function shippingFee(subtotal, isMember, isDomestic) {
  let fee;
  if (!isDomestic) {
    fee = 25;
  } else if (subtotal >= 50) {
    fee = 0;
  } else if (isMember) {
    fee = 2;
  } else {
    fee = 5;
  }
  return fee;
}
V(G) P + 1 = 3 + 1 = 4 E − N + 2 = 10 − 8 + 2 = 4
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-8subtotal = 30, isMember = false, isDomestic = false25
1-3-4-8subtotal = 80, isMember = false, isDomestic = true0
1-3-5-6-8subtotal = 20, isMember = true, isDomestic = true2
1-3-5-7-8subtotal = 20, isMember = false, isDomestic = true5
  • سلسلة else if = عقدة قرار لكل شرط.An else-if chain = one decision node per condition.
  • متغيّر fee وreturn واحد يعطيان المخطط نهاية واحدة (8).One fee variable and one return give the graph a single exit (8).

عضو، محلي، المبلغ 80. أي مسار؟Member, domestic, subtotal 80. Which path?

4

قفل الحساب بعد محاولات خاطئةAccount lockout after wrong attempts

خدمة المصادقة في تطبيق محفظة: إن كان الحساب مقفلًا نرفض، وبعد 3 محاولات خاطئة نطلب OTP.An e-wallet’s auth service: if the account is locked we refuse; after 3 wrong attempts we require an OTP.

صندوق أبيض · White box جوال · Mobile nested if V(G)=4
function loginAttempt(passwordOk, failedBefore, lockedMinutes) {
  let result = 'ok', failed = failedBefore;
  if (lockedMinutes > 0) {
    result = 'locked';
  } else if (!passwordOk) {
    failed++;
    if (failed >= 3) {
      result = 'otp-required';
    } else {
      result = 'wrong-password';
    }
  }
  return result;
}
V(G) P + 1 = 3 + 1 = 4 E − N + 2 = 11 − 9 + 2 = 4
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-3-9passwordOk = true, failedBefore = 0, lockedMinutes = 5locked
1-2-4-9passwordOk = true, failedBefore = 0, lockedMinutes = 0ok
1-2-4-5-6-7-9passwordOk = false, failedBefore = 2, lockedMinutes = 0otp-required
1-2-4-5-6-8-9passwordOk = false, failedBefore = 0, lockedMinutes = 0wrong-password
  • الـ if المتداخل يضيف عقدة قرار (6) داخل الفرع.The nested if adds a decision node (6) inside a branch.
  • قارن بمجموعة اختبارات الصندوق الأسود لنفس الميزة في الدروس.Compare with the black-box login suite for the same feature in the lessons.

كلمة مرور خاطئة، محاولتان سابقتان، غير مقفل. النتيجة؟Wrong password, 2 failed before, not locked. Result?

5

كوبونات الخصم بـ switchDiscount coupons with switch

SAVE10 خصم 10%، FREESHIP خصم 5، WELCOME خصم 15 لأول طلب فقط، وأي كود آخر بلا خصم.SAVE10 takes 10% off, FREESHIP takes 5 off, WELCOME takes 15 off on the first order only, any other code nothing.

صندوق أبيض · White box ويب · Web switch V(G)=5
function applyCoupon(total, code, isFirstOrder) {
  let discount = 0;
  switch (code) {
    case 'SAVE10':
      discount = total * 0.1; break;
    case 'FREESHIP':
      discount = 5; break;
    case 'WELCOME':
      if (isFirstOrder) { discount = 15; }
      break;
  }
  return Math.max(0, total - discount);
}
V(G) P + 1 = 4 + 1 = 5 E − N + 2 = 10 − 7 + 2 = 5
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-3-7total = 80, code = "SAVE10", isFirstOrder = false72
1-2-4-7total = 80, code = "FREESHIP", isFirstOrder = false75
1-2-5-6-7total = 80, code = "WELCOME", isFirstOrder = true65
1-2-5-7total = 80, code = "WELCOME", isFirstOrder = false80
1-2-7total = 80, code = "HELLO", isFirstOrder = false80
  • switch بأربعة مخارج يُحسب 3 قرارات (المخارج − 1).A switch with four exits counts as 3 decisions (exits − 1).
  • لا تنسَ فرع default الضمني: كود غير معروف.Do not forget the implicit default branch: an unknown code.

لماذا V(G) = 5؟Why is V(G) = 5?

6

قوة كلمة المرور في نموذج التسجيلPassword strength in a sign-up form

نقطة للطول ≥ 8، ونقطة لوجود رقم، ونقطة لحرف كبير. ثلاث جمل if متتالية.A point for length ≥ 8, a point for a digit, a point for a capital letter. Three ifs in a row.

صندوق أبيض · White box ويب + جوال · Web + Mobile sequential if V(G)=4
function passwordScore(password) {
  let score = 0;
  if (password.length >= 8) { score++; }
  if (/[0-9]/.test(password)) { score++; }
  if (/[A-Z]/.test(password)) { score++; }
  return score;
}
V(G) P + 1 = 3 + 1 = 4 E − N + 2 = 10 − 8 + 2 = 4
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-3-4-5-6-7-8password = "Secret12"3
1-2-4-5-6-7-8password = "A1"2
1-2-3-4-6-7-8password = "Password"2
1-2-3-4-5-6-8password = "secret12"2
  • عدد كل المسارات 2³ = 8، لكن المستقلّة 4 فقط.There are 2³ = 8 full paths, but only 4 basis paths.
  • كل مسار مستقل يقلب قرارًا واحدًا عن المسار الأول.Each basis path flips one decision compared to the first path.

كم مسارًا كاملًا ممكنًا؟How many full paths are possible?

7

إعادة المحاولة مع breakRetry with break

التطبيق يعيد الطلب عند أخطاء 5xx، والانتظار يتضاعف (1، 2، 4…). يتوقف عند أول رد ناجح.The app retries on 5xx errors with doubling waits (1, 2, 4…). It stops at the first successful response.

صندوق أبيض · White box جوال · Mobile while break V(G)=3
function totalWait(statuses) {
  let wait = 0, delay = 1, i = 0;
  while (i < statuses.length) {
    if (statuses[i] < 500) { break; }
    wait += delay; delay *= 2; i++;
  }
  return wait;
}
V(G) P + 1 = 2 + 1 = 3 E − N + 2 = 7 − 6 + 2 = 3
المسار · Pathالمدخل · Inputالمتوقّع · Expected
1-2-6statuses = []0
1-2-3-4-6statuses = [200]0
1-2-3-5-2-6statuses = [503]1
  • break يخرج من الحلقة مباشرة: السهم 4 ← 6.break leaves the loop at once: edge 4 → 6.
  • جرّب [503, 503, 200] في المختبر: الانتظار 1 + 2 = 3.Try [503, 503, 200] in the lab: the wait is 1 + 2 = 3.

أي سهم يمثّل break؟Which edge is the break?

8

توصيل مجاني من 50Free delivery from 50

تطبيق توصيل طعام. اختبر رسوم التوصيل بدون رؤية الكود.A food delivery app. Test the delivery fee without seeing the code.

صندوق أسود · Black box جوال · Mobile BVA ≥
المواصفة · Specالتوصيل مجاني (0) عندما يكون المبلغ 50 أو أكثر، وإلا فالرسوم 4. المبلغ السالب يعيد error.Delivery is free (0) when the subtotal is 50 or more, otherwise the fee is 4. A negative subtotal returns error.
الفئة · Classمثال · Sample
سالب (غير صالح)Negative (invalid) -5
من 0 إلى أقل من 500 up to below 50 20
50 فأكثر50 and above 80
القيم الحدّية · Boundaries
-0.01 0 49.99 50 50.01
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1مبلغ صغيرSmall order subtotal = 204
TC2مبلغ كبيرBig order subtotal = 800
TC3على الحدّ تمامًاExactly on the boundary subtotal = 500
TC4تحت الحدّ مباشرةJust below the boundary subtotal = 49.994
TC5مبلغ سالبNegative subtotal subtotal = -5error
  • الاختبارات 20 و 80 تنجح حتى مع وجود الخطأ. الحدّ 50 هو ما يكشفه.Tests with 20 and 80 pass even with the bug. Only the boundary 50 reveals it.

أي قيمة الأهم هنا؟Which value matters most here?

9

عمر التسجيل في منصة تواصلSign-up age on a social platform

نموذج تسجيل يتحقّق من العمر. لا نرى الكود، فقط المواصفة.A sign-up form checks the age. We do not see the code, only the spec.

صندوق أسود · Black box ويب · Web EP BVA
المواصفة · Specالعمر المقبول من 13 إلى 120 (شاملًا) ← ok، وغير ذلك ← rejected.Ages 13 to 120 (inclusive) → ok, anything else → rejected.
الفئة · Classمثال · Sample
أقل من 13Below 13 8
13 إلى 12013 to 120 25
أكثر من 120Above 120 150
القيم الحدّية · Boundaries
12 13 120 121
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1عمر عاديA normal age age = 25ok
TC2صغير جدًاToo young age = 12rejected
TC3الحدّ الأدنىLower boundary age = 13ok
TC4الحدّ الأعلىUpper boundary age = 120ok
TC5فوق الحدّAbove the range age = 121rejected
  • 3 فئات × حدّان = اختبارات قليلة تكشف الكثير.3 classes × 2 edges = few tests that find a lot.

كم فئة تكافؤ للعمر؟How many equivalence classes does age have?

10

كمية المنتج في السلةItem quantity in the cart

زر «أضف للسلة» يرسل الكمية لخدمة السلة. اختبر الخدمة من الخارج.The “Add to cart” button sends a quantity to the cart service. Test the service from outside.

صندوق أسود · Black box ويب + جوال · Web + Mobile EP BVA
المواصفة · Specالكمية من 1 إلى 10 ← added، وأقل من 1 أو أكثر من 10 ← error.A quantity from 1 to 10 → added; below 1 or above 10 → error.
الفئة · Classمثال · Sample
أقل من 1Below 1 -2
1 إلى 101 to 10 4
أكثر من 10Above 10 15
القيم الحدّية · Boundaries
0 1 10 11
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1كمية عاديةNormal quantity qty = 4added
TC2صفرZero qty = 0error
TC3الحدّ الأدنىMinimum qty = 1added
TC4الحدّ الأعلىMaximum qty = 10added
TC5فوق الحدّOver the maximum qty = 11error
  • القيمة -2 تمثّل الفئة غير الصالحة لكنها لا تكشف الخطأ. الحدّ 0 يكشفه.-2 represents the invalid class but does not reveal the bug. The boundary 0 does.

ما القيم الحدّية؟Which are the boundary values?

11

صيغة رمز OTPOTP code format

شاشة إدخال رمز التحقّق في تطبيق بنكي. نختبر قبول الرمز قبل إرساله للخادم.The verification code screen of a banking app. We test which codes are accepted before sending them to the server.

صندوق أسود · Black box جوال · Mobile text length
المواصفة · Specالرمز صالح إذا كان 6 أرقام بالضبط ← valid، وغير ذلك ← invalid.A code is valid if it is exactly 6 digits → valid, otherwise → invalid.
الفئة · Classمثال · Sample
أقل من 6 أرقامFewer than 6 digits 123
6 أرقامExactly 6 digits 482913
أكثر من 6 أرقامMore than 6 digits 12345678
فيه حروفHas letters 12a456
القيم الحدّية · Boundaries
12345 123456 1234567
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1رمز صحيحA correct code code = "482913"valid
TC25 أرقام5 digits code = "12345"invalid
TC37 أرقام7 digits code = "1234567"invalid
TC4حرف داخل الرمزA letter inside code = "12a456"invalid
  • الحدود تنطبق على الأطوال أيضًا، لا على الأرقام فقط.Boundaries apply to lengths too, not only to numbers.

أي أطوال تختبر الحدود؟Which lengths test the boundaries?

12

تسعير ساعة الذروة في تطبيق رحلاتRush-hour pricing in a ride app

الأجرة الأساسية 10. في الذروة تُضرب بـ 1.5.The base fare is 10. In rush hour it is multiplied by 1.5.

صندوق أسود · Black box جوال · Mobile ranges BVA
المواصفة · Specالذروة من الساعة 17 إلى 19 (شاملًا) ← 15، باقي الساعات ← 10، والساعة خارج 0–23 ← error.Rush hour is 17 to 19 (inclusive) → 15, other hours → 10, an hour outside 0–23 → error.
الفئة · Classمثال · Sample
ساعة غير صالحةInvalid hour 25
خارج الذروةOff-peak 10
الذروةRush hour 18
القيم الحدّية · Boundaries
-1 0 16 17 19 20 23 24
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1صباحًاMorning hour = 1010
TC2بداية الذروةRush hour starts hour = 1715
TC3آخر ساعة ذروةLast rush hour hour = 1915
TC4بعد الذروةRight after rush hour hour = 2010
TC5ساعة غير موجودةAn hour that does not exist hour = 24error
  • مدى داخل مدى: حدود 0–23 وحدود 17–19 كلها تستحق الاختبار.A range inside a range: the edges of 0–23 and of 17–19 all deserve a test.

أي ساعة تكشف خطأ «‎<= 20‎ بدل ‎<= 19‎»؟Which hour reveals “<= 20 instead of <= 19”?

13

قواعد اسم المستخدمUsername rules

منصة ألعاب على الويب تتحقّق من اسم المستخدم عند التسجيل.A web gaming platform validates the username at sign-up.

صندوق أسود · Black box ويب · Web EP text
المواصفة · Specمن 3 إلى 20 حرفًا، حروف إنجليزية وأرقام و _ فقط، ويجب أن يبدأ بحرف ← ok، وإلا ← invalid.3 to 20 characters, English letters, digits and _ only, and it must start with a letter → ok, otherwise → invalid.
الفئة · Classمثال · Sample
صالحValid sara_99
قصير جدًاToo short ab
طويل جدًاToo long a_very_long_username_x
رمز غير مسموحForbidden symbol sara!
لا يبدأ بحرفDoes not start with a letter 9sara
القيم الحدّية · Boundaries
ab abc a + 19 chars a + 20 chars
#الملخص · Summaryالمدخل · Inputالمتوقّع · Expected
TC1اسم صالحA valid name username = "sara_99"ok
TC2قصيرToo short username = "ab"invalid
TC3رمز !Has ! username = "sara!"invalid
TC4يبدأ برقمStarts with a digit username = "9sara"invalid
  • هنا الخطأ ليس على حدّ رقمي: إنها فئة كاملة منسية. لكل قاعدة في المواصفة فئة.Here the bug is not at a numeric edge: a whole class was forgotten. Every rule in the spec deserves its own class.

أي قيمة تمثّل فئة «لا يبدأ بحرف»؟Which value represents “does not start with a letter”?