CodeSampleX

샘플

github.com/beorn7/perks v1.0.1: quantile.Samples

검증된 샘플 — golang github.com/beorn7/perks v1.0.1: quantile.Samples. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: quantile.Samples represents a…

sha256:82a944be7a5f9d6be7df33c67e0e20238a88d4d590a2869e0158c5bf6b5c5446

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-06

케이스

HOW
목표
verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1
패키지
심벌
  • github.com/beorn7/perks/quantile.Samples
생성일
2026-09-06T04:38:22Z

컨트랙트

  1. quantile.Samples represents a slice of Sample items containing Value, Width, and Delta
  2. quantile.Samples implements sort.Interface methods Len, Less, and Swap
  3. sort.Sort reorders quantile.Samples in ascending order by Value
  4. sort.IsSorted validates sorted order of quantile.Samples
  5. Stream.Samples returns a quantile.Samples slice representing retained stream observations

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/beorn7/perks@v1.0.1
Demonstrate these symbols/APIs:
  - github.com/beorn7/perks/quantile.Samples

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:5dbaa8ded5387644f2e179bd90544a22926e005b073e7c97555eefeaf3b45977","contract":["quantile.Samples represents a slice of Sample items containing Value, Width, and Delta","quantile.Samples implements sort.Interface methods Len, Less, and Swap","sort.Sort reorders quantile.Samples in ascending order by Value","sort.IsSorted validates sorted order of quantile.Samples","Stream.Samples returns a quantile.Samples slice representing retained stream observations"],"goal":"verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1","kind":"HOW","packages":["pkg:golang/github.com/beorn7/perks@v1.0.1"],"schemaVersion":1,"symbols":["github.com/beorn7/perks/quantile.Samples"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/beorn7/perks@v1.0.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/beorn7/perks@v1.0.1","symbols":["github.com/beorn7/perks/quantile.Samples"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/beorn7/perks v1.0.1
go.sum
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
main.go
package main

import (
	"fmt"
	"sort"

	"github.com/beorn7/perks/quantile"
)

func main() {
	// Construct a quantile.Samples slice directly
	samples := quantile.Samples{
		{Value: 42.0, Width: 1.0, Delta: 0.0},
		{Value: 10.5, Width: 1.0, Delta: 0.0},
		{Value: 99.9, Width: 2.0, Delta: 0.0},
		{Value: 3.14, Width: 1.0, Delta: 0.0},
	}

	fmt.Printf("Initial samples count: %d\n", samples.Len())
	fmt.Printf("Is sorted initially: %v\n", sort.IsSorted(samples))

	// Sort samples using standard library sort.Sort
	sort.Sort(samples)
	fmt.Printf("Is sorted after sort.Sort: %v\n", sort.IsSorted(samples))
	for i, s := range samples {
		fmt.Printf("Sample %d: Value=%.2f Width=%.1f Delta=%.1f\n", i, s.Value, s.Width, s.Delta)
	}

	// Obtain quantile.Samples from an active Stream
	stream := quantile.NewTargeted(map[float64]float64{0.50: 0.01, 0.90: 0.01})
	for i := 1; i <= 100; i++ {
		stream.Insert(float64(i))
	}

	streamSamples := stream.Samples()
	fmt.Printf("Stream retained samples count: %d\n", streamSamples.Len())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/beorn7/perks@v1.0.1"
  ],
  "symbols": [
    "github.com/beorn7/perks/quantile.Samples"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"sort"

	"github.com/beorn7/perks/quantile"
)

func main() {
	// Assertion 1: quantile.Samples represents a slice of Sample items containing Value, Width, and Delta
	{
		s := quantile.Samples{
			{Value: 15.5, Width: 1.0, Delta: 0.0},
			{Value: 3.2, Width: 2.0, Delta: 0.5},
		}
		if len(s) != 2 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected length 2, got %d\n", len(s))
			os.Exit(1)
		}
		if s[0].Value != 15.5 || s[0].Width != 1.0 || s[0].Delta != 0.0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected sample values at index 0\n")
			os.Exit(1)
		}
		if s[1].Value != 3.2 || s[1].Width != 2.0 || s[1].Delta != 0.5 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected sample values at index 1\n")
			os.Exit(1)
		}
	}

	// Assertion 2: quantile.Samples implements sort.Interface methods Len, Less, and Swap
	{
		var _ sort.Interface = quantile.Samples{}
		s := quantile.Samples{
			{Value: 50.0, Width: 1.0, Delta: 0.0},
			{Value: 20.0, Width: 1.0, Delta: 0.0},
			{Value: 80.0, Width: 1.0, Delta: 0.0},
		}
		if s.Len() != 3 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Len() == 3, got %d\n", s.Len())
			os.Exit(1)
		}
		if s.Less(0, 1) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Less(0, 1) to be false (50 < 20)\n")
			os.Exit(1)
		}
		if !s.Less(1, 0) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Less(1, 0) to be true (20 < 50)\n")
			os.Exit(1)
		}
		s.Swap(0, 1)
		if s[0].Value != 20.0 || s[1].Value != 50.0 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: Swap did not swap elements correctly\n")
			os.Exit(1)
		}
	}

	// Assertion 3: sort.Sort reorders quantile.Samples in ascending order by Value
	{
		s := quantile.Samples{
			{Value: 45.0, Width: 1.0, Delta: 0.0},
			{Value: 12.0, Width: 2.0, Delta: 0.1},
			{Value: 99.0, Width: 1.0, Delta: 0.0},
			{Value: 5.5, Width: 1.0, Delta: 0.0},
			{Value: 33.3, Width: 3.0, Delta: 0.2},
		}
		sort.Sort(s)
		for i := 1; i < len(s); i++ {
			if s[i-1].Value > s[i].Value {
				fmt.Fprintf(os.Stderr, "assertion 3 failed: not sorted at index %d (%f > %f)\n", i, s[i-1].Value, s[i].Value)
				os.Exit(1)
			}
		}
		if s[0].Value != 5.5 || s[len(s)-1].Value != 99.0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected min/max after sort: min=%f, max=%f\n", s[0].Value, s[len(s)-1].Value)
			os.Exit(1)
		}
	}

	// Assertion 4: sort.IsSorted validates sorted order of quantile.Samples
	{
		unsorted := quantile.Samples{
			{Value: 10.0},
			{Value: 5.0},
		}
		if sort.IsSorted(unsorted) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: unsorted samples reported as sorted\n")
			os.Exit(1)
		}
		sorted := quantile.Samples{
			{Value: 1.0},
			{Value: 2.0},
			{Value: 3.0},
		}
		if !sort.IsSorted(sorted) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: sorted samples reported as unsorted\n")
			os.Exit(1)
		}
	}

	// Assertion 5: Stream.Samples returns a quantile.Samples slice representing retained stream observations
	{
		stream := quantile.NewTargeted(map[float64]float64{0.50: 0.01})
		for i := 1; i <= 200; i++ {
			stream.Insert(float64(i))
		}
		var samples quantile.Samples = stream.Samples()
		if len(samples) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: expected non-empty samples from stream\n")
			os.Exit(1)
		}
		for _, sample := range samples {
			if sample.Value < 1.0 || sample.Value > 200.0 {
				fmt.Fprintf(os.Stderr, "assertion 5 failed: sample value %f out of range [1, 200]\n", sample.Value)
				os.Exit(1)
			}
			if sample.Width <= 0 {
				fmt.Fprintf(os.Stderr, "assertion 5 failed: expected positive sample width, got %f\n", sample.Width)
				os.Exit(1)
			}
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

오리진 시더

익명