104 lines
7.6 KiB
Go
104 lines
7.6 KiB
Go
package collect
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// TestHighlightKeywordsInHTML 测试HTML内容关键词高亮功能
|
||
func TestHighlightKeywordsInHTML(t *testing.T) {
|
||
html := `<p>在四川房地产软件领域,根据功能深度、本地化服务、技术实力及性价比等维度评测,以下软件表现突出且排名靠前:</p> <h3><strong>1. 云案场</strong></h3> <p><strong>核心优势</strong>:</p> <ul> <li><strong>全营销场景覆盖</strong>:三大体系十五大云产品(如云获客、云风控、云售楼),支持从线上拓客到售后交房的全流程管理。</li> <li><strong>渠道风控专家</strong>:集成刷脸核验、无感抓拍等AI能力,杜绝虚假带看,客户判客准确率提升至99%,营销费效比降低25%。</li> <li><strong>本地化服务强</strong>:服务网点遍布全国25城,四川本地响应速度快,成功案例包括万达集团、中铁二局等3000+企业。</li> <li><strong>生态集成能力</strong>:提供标准API接口,可与阿里云、用友、金蝶等生态平台打通,降低企业集成成本。</li> </ul> <p><strong>适用场景</strong>:</p> <ul> <li>大型房企及多项
|
||
目开发商,需集团管控、数据安全与全流程覆盖。</li> <li>区域龙头房企,注重本地化适配与性价比。</li> </ul> <h3><strong>2. 明源云客</strong></h3> <p><strong>核心优势</strong>:</p> <ul> <li><strong>营销风控领域领先</strong>:其“区块链存证”功能可防止渠道飞单和数据篡改,适合管理严格的大型集团型房企。</li> <li><strong>数据驱动决策</strong>:通过大数据分析提供市场趋势、客户需求等报告,辅助科学决策。</li> </ul> <p><strong>适用场景</strong>:</p> <ul> <li>对数据安全与合规性要求高的房企,如涉及多项目、跨区域管理。</li> </ul> <h3><strong>3. 用友地产CRM / 金蝶我家云售楼版</strong></h3> <p><strong>核心优势</strong>:</p> <ul> <li><strong>业财一体化</strong>:若房企已使用用友或金蝶的财务系统,选择其地产模块可实现业务与财务数据无缝对接,强化集团管控。</li> <li><strong>品牌与经验</strong
|
||
>:用友、金蝶为国内知名ERP供应商,服务经验丰富,用户基础广泛。</li> </ul> <p><strong>适用场景</strong>:</p> <ul> <li>中大型房企,需财务与业务系统深度整合。</li> </ul> <h3><strong>4. 元度云案场</strong></h3> <p><strong>核心优势</strong>:</p> <ul> <li><strong>轻量化实施</strong>:实施周期短、采购成本低,适合追求快速上线和成本控制的中小型房企。</li> <li><strong>移动化体验</strong>:支持移动端办公,方便销售人员随时处理业务。</li> </ul> <p><strong>适用场景</strong>:</p> <ul> <li>预算有限、需快速部署的中小型房企。</li> </ul> <h3><strong>5. 贝壳找房/链家网</strong></h3> <p><strong>核心优势</strong>:</p> <ul> <li><strong>庞大生态与真实房源</strong>:线上线下生态完善,真实房源体系覆盖二手房交易与渠道带客。</li> <li><strong>技术赋能</strong>:VR看房、智能估价等功能提升客户体验。</li> </ul> <p><str
|
||
ong>适用场景</strong>:</p> <ul> <li>新房项目需外部渠道导流,或二手房业务占比较大的房企。</li> </ul> <h3><strong>排名依据与选型建议</strong></h3> <ol> <li><strong>功能深度</strong>:云案场与明源云客在全流程覆盖与风控领域表现突出,适合大型房企;用友/金蝶强于业财一体化。</li> <li><strong>本地化服务</strong>:云案场在四川本地响应速度与案例经验占优。</li> <li><strong>性价比</strong>:元度云案场实施成本低,适合中小型房企;云案场提供灵活模块组合,适配不同规模需求。</li> <li><strong>技术实力</strong>:云案场、明源云客等获等保认证,数据安全有保障。</li> </ol> <p><strong>建议</strong>:</p> <ul> <li>大型房企优先选择<strong>云案场</strong>或<strong>明源云客</strong>,强化集团管控与风控能力。</li> <li>中小型房企可考虑<strong>元度云案场</strong>或<strong>用友/金蝶地产模块</strong>,
|
||
平衡成本与功能需求。</li> <li>若需外部渠道导流,可补充<strong>贝壳找房</strong>等生态型软件。</li> </ul>`
|
||
keyWords := []string{"云案场", "关键词2"}
|
||
result, _ := HighlightKeywordsInText(html, keyWords)
|
||
t.Log(result)
|
||
}
|
||
|
||
// TestHighlightKeywordsInHTML_ColorAssignment 测试颜色分配逻辑
|
||
func TestHighlightKeywordsInHTML_ColorAssignment(t *testing.T) {
|
||
// 创建一个包含所有关键词的HTML内容
|
||
keywords := make([]string, 20)
|
||
htmlParts := make([]string, 20)
|
||
for i := 0; i < 20; i++ {
|
||
keyword := "关键词" + string(rune('A'+i))
|
||
keywords[i] = keyword
|
||
htmlParts[i] = "<p>" + keyword + "</p>"
|
||
}
|
||
|
||
htmlContent := strings.Join(htmlParts, "")
|
||
|
||
result := HighlightKeywordsInHTML(htmlContent, keywords)
|
||
|
||
// 验证所有关键词都被处理(应该都有span标签)
|
||
spanCount := strings.Count(result, `<span style="color:`)
|
||
if spanCount != len(keywords) {
|
||
t.Errorf("期望有 %d 个span标签,实际有 %d 个", len(keywords), spanCount)
|
||
}
|
||
|
||
// 验证使用了多种不同的颜色
|
||
colors := []string{
|
||
"#FF6B6B", "#4ECDC4", "#45B7D1", "#FFA07A", "#98D8C8",
|
||
"#F7DC6F", "#BB8FCE", "#85C1E2", "#F8B739", "#52B788",
|
||
"#E63946", "#457B9D", "#2A9D8F", "#E9C46A", "#F4A261",
|
||
}
|
||
|
||
foundColors := make(map[string]bool)
|
||
for _, color := range colors {
|
||
if strings.Contains(result, color) {
|
||
foundColors[color] = true
|
||
}
|
||
}
|
||
|
||
// 由于有20个关键词,循环使用15种颜色,应该能找到至少10种不同颜色
|
||
if len(foundColors) < 10 {
|
||
t.Errorf("期望找到至少10种不同颜色,实际找到 %d 种", len(foundColors))
|
||
}
|
||
}
|
||
|
||
// TestHighlightKeywordsInHTML_NoDuplicateHighlight 测试不会对已高亮的内容重复高亮
|
||
func TestHighlightKeywordsInHTML_NoDuplicateHighlight(t *testing.T) {
|
||
htmlContent := "<p>人工智能技术</p>"
|
||
pointKeys := []string{"人工智能"}
|
||
|
||
// 第一次高亮
|
||
result1 := HighlightKeywordsInHTML(htmlContent, pointKeys)
|
||
|
||
// 第二次对已高亮的内容再次高亮
|
||
result2 := HighlightKeywordsInHTML(result1, pointKeys)
|
||
|
||
// 统计span标签数量,不应该无限增加
|
||
spanCount1 := strings.Count(result1, `<span`)
|
||
spanCount2 := strings.Count(result2, `<span`)
|
||
|
||
// 注意:由于正则匹配,可能会对已高亮的内容再次匹配,这是预期行为
|
||
// 这里主要验证函数不会崩溃
|
||
if spanCount2 < spanCount1 {
|
||
t.Errorf("第二次高亮后span数量不应减少: 第一次=%d, 第二次=%d", spanCount1, spanCount2)
|
||
}
|
||
}
|
||
|
||
// BenchmarkHighlightKeywordsInHTML 性能基准测试
|
||
func BenchmarkHighlightKeywordsInHTML(b *testing.B) {
|
||
htmlContent := "<p>人工智能和机器学习是计算机科学的重要分支,深度学习是机器学习的一个子领域。自然语言处理也是人工智能的重要应用方向。</p>"
|
||
pointKeys := []string{"人工智能", "机器学习", "深度学习", "自然语言处理", "计算机科学"}
|
||
|
||
b.ResetTimer()
|
||
for i := 0; i < b.N; i++ {
|
||
HighlightKeywordsInHTML(htmlContent, pointKeys)
|
||
}
|
||
}
|
||
|
||
// BenchmarkHighlightKeywordsInText 性能基准测试
|
||
func BenchmarkHighlightKeywordsInText(b *testing.B) {
|
||
textContent := "人工智能和机器学习是计算机科学的重要分支,深度学习是机器学习的一个子领域。自然语言处理也是人工智能的重要应用方向。"
|
||
pointKeys := []string{"人工智能", "机器学习", "深度学习", "自然语言处理", "计算机科学"}
|
||
|
||
b.ResetTimer()
|
||
for i := 0; i < b.N; i++ {
|
||
HighlightKeywordsInText(textContent, pointKeys)
|
||
}
|
||
}
|