algorithm.spec.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const { test, expect } = require('@playwright/test');
  2. const BASE_URL = 'https://ajy.danclub.cn';
  3. const API_BASE_URL = 'https://ajy.danclub.cn/api';
  4. /**
  5. * 核心算法测试
  6. * 测试指寸估算算法、穴位坐标生成、数据验证、置信度计算
  7. */
  8. test.describe('6.1 指寸估算算法', () => {
  9. test('AL-001: 男性标准体型估算', async ({ request }) => {
  10. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  11. data: { shoulderWidth: 42, bodyLength: 85, gender: '男' }
  12. });
  13. const data = await response.json();
  14. expect(data.cun1).toBeCloseTo(2.2, 0.1);
  15. });
  16. test('AL-002: 女性标准体型估算', async ({ request }) => {
  17. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  18. data: { shoulderWidth: 36, bodyLength: 78, gender: '女' }
  19. });
  20. const data = await response.json();
  21. expect(data.cun1).toBeCloseTo(1.9, 0.1);
  22. });
  23. test('AL-003: 男性大体型估算', async ({ request }) => {
  24. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  25. data: { shoulderWidth: 52, bodyLength: 95, gender: '男' }
  26. });
  27. const data = await response.json();
  28. expect(data.cun1).toBeCloseTo(2.54, 0.1);
  29. });
  30. test('AL-004: 男性小体型估算', async ({ request }) => {
  31. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  32. data: { shoulderWidth: 36, bodyLength: 75, gender: '男' }
  33. });
  34. const data = await response.json();
  35. expect(data.cun1).toBeCloseTo(1.88, 0.1);
  36. });
  37. test('AL-005: 女性大体型估算', async ({ request }) => {
  38. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  39. data: { shoulderWidth: 46, bodyLength: 88, gender: '女' }
  40. });
  41. const data = await response.json();
  42. expect(data.cun1).toBeCloseTo(2.26, 0.1);
  43. });
  44. test('AL-006: 女性小体型估算', async ({ request }) => {
  45. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  46. data: { shoulderWidth: 32, bodyLength: 70, gender: '女' }
  47. });
  48. const data = await response.json();
  49. expect(data.cun1).toBeCloseTo(1.54, 0.1);
  50. });
  51. test('AL-007: 有指寸不估算', async ({ request }) => {
  52. const response = await request.post(`${API_BASE_URL}/algorithm/cun-calculate`, {
  53. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', providedCun: { cun1: 2.0 } }
  54. });
  55. const data = await response.json();
  56. expect(data.cun1).toBe(2.0);
  57. expect(data.estimated).toBe(false);
  58. });
  59. });
  60. test.describe('6.2 穴位对照表生成', () => {
  61. test('AL-010: 生成12个穴位', async ({ request }) => {
  62. const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
  63. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
  64. });
  65. const data = await response.json();
  66. expect(data.acupoints.length).toBeGreaterThanOrEqual(20);
  67. });
  68. test('AL-011: 大椎穴为原点', async ({ request }) => {
  69. const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
  70. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
  71. });
  72. const data = await response.json();
  73. const dazhui = data.acupoints.find(a => a.name === '大椎');
  74. expect(dazhui.x).toBe(0);
  75. expect(dazhui.y).toBe(0);
  76. });
  77. test('AL-012: 督脉只有纵向偏移', async ({ request }) => {
  78. const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
  79. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
  80. });
  81. const data = await response.json();
  82. const dumaiPoints = data.acupoints.filter(a => a.meridian === '督脉');
  83. dumaiPoints.forEach(p => {
  84. expect(p.x).toBe(0);
  85. });
  86. });
  87. test('AL-013: 双侧穴位横向偏移', async ({ request }) => {
  88. const response = await request.post(`${API_BASE_URL}/algorithm/acupoint-generate`, {
  89. data: { shoulderWidth: 42, bodyLength: 85, gender: '男', cun1: 2.2 }
  90. });
  91. const data = await response.json();
  92. const doubleSidePoints = data.acupoints.filter(a => a.side === '双侧');
  93. const hasPositiveX = doubleSidePoints.some(p => p.x > 0);
  94. const hasNegativeX = doubleSidePoints.some(p => p.x < 0);
  95. expect(hasPositiveX).toBe(true);
  96. expect(hasNegativeX).toBe(true);
  97. });
  98. });
  99. test.describe('6.3 数据验证', () => {
  100. test('AL-020: 男性肩宽边界-通过', async ({ request }) => {
  101. const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
  102. data: { shoulderWidth: 36, gender: '男' }
  103. });
  104. const data = await response.json();
  105. expect(data.valid).toBe(true);
  106. });
  107. test('AL-021: 男性肩宽边界-不通过', async ({ request }) => {
  108. const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
  109. data: { shoulderWidth: 35, gender: '男' }
  110. });
  111. const data = await response.json();
  112. expect(data.valid).toBe(false);
  113. expect(data.error).toContain('36-52');
  114. });
  115. test('AL-022: 女性身长边界-通过', async ({ request }) => {
  116. const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
  117. data: { bodyLength: 88, gender: '女' }
  118. });
  119. const data = await response.json();
  120. expect(data.valid).toBe(true);
  121. });
  122. test('AL-023: 女性身长边界-不通过', async ({ request }) => {
  123. const response = await request.post(`${API_BASE_URL}/algorithm/validate`, {
  124. data: { bodyLength: 89, gender: '女' }
  125. });
  126. const data = await response.json();
  127. expect(data.valid).toBe(false);
  128. expect(data.error).toContain('70-88');
  129. });
  130. test('AL-024: 指寸范围验证', async ({ request }) => {
  131. const response = await request.post(`${API_BASE_URL}/algorithm/validate-cun`, {
  132. data: { cun: 1.2, gender: '女' }
  133. });
  134. const data = await response.json();
  135. expect(data.valid).toBe(false);
  136. });
  137. });
  138. test.describe('6.4 置信度计算', () => {
  139. test('AL-030: 仅肩宽身长', async ({ request }) => {
  140. const response = await request.post(`${API_BASE_URL}/algorithm/confidence`, {
  141. data: { shoulderWidth: 42, bodyLength: 85 }
  142. });
  143. const data = await response.json();
  144. expect(data.confidence).toBe(50);
  145. expect(data.precision).toBe('±5cm');
  146. });
  147. test('AL-031: 部分指寸', async ({ request }) => {
  148. const response = await request.post(`${API_BASE_URL}/algorithm/confidence`, {
  149. data: { shoulderWidth: 42, bodyLength: 85, cun1: 2.2 }
  150. });
  151. const data = await response.json();
  152. expect(data.confidence).toBe(65);
  153. expect(data.precision).toBe('±4cm');
  154. });
  155. test('AL-032: 完整指寸', async ({ request }) => {
  156. const response = await request.post(`${API_BASE_URL}/algorithm/confidence`, {
  157. data: { shoulderWidth: 42, bodyLength: 85, cun1: 2.2, cun1_5: 3.3, cun3: 6.6 }
  158. });
  159. const data = await response.json();
  160. expect(data.confidence).toBe(95);
  161. expect(data.precision).toBe('±2cm');
  162. });
  163. });