File size: 1,264 Bytes
3f69d68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from lightnest.probe_patch_limits import freeze, assess, signed
from lightnest.learned_patch import LearnedPatch

def test_frozen_deterministic_and_reference_oracles():
    entries=freeze(2)
    assert entries==freeze(2)
    assert len(entries)==24
    for entry in entries:
        result=assess(entry,None)
        if entry['expected'] is None:
            assert result['category']=='unsupported_no_oracle_abstention'
        elif entry['family'] in ('negation','keep_unchanged','already_correct'):
            assert result['category']=='correct_negative_abstention'
        else:
            assert result['category']=='positive_abstention'

def test_single_correct_patch_and_negation_damage():
    entries=freeze(1)
    for family,wanted in [('single_control','positive_pass'),('negation','negative_destructive_proposal')]:
        e=next(x for x in entries if x['family']==family)
        binary=bytes.fromhex(e['binary_hex'])
        # Only the single ADD in these fixtures can carry opcode 0x33.
        offset=next(i+3 for i in range(0,len(binary),4) if binary[i]&127==0x33)
        patch=LearnedPatch(offset,binary[offset],binary[offset]^0x40)
        assert assess(e,patch)['category']==wanted

def test_signed_wrap():
    assert signed(2**31)==-2**31